This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
Support custom assets prefix for webpack #1217
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relate to an old issue 437.
Support use custom assets prefix to serve static files like js and css, but currently only for webpack users since I'm not familiar with rollup. Still figuring how to solve this using rollup.
Personally, I think it's an important feature because there is a lot of companies use a different domain to serve their static files in order to bypass the browser request restriction of the same domain and to reduce meaningless bandwidth consumption generated by cookie.
For me, I like sapper and want to use it for our company's project, but this problem is completely preventing me from using it. I can't find any workaround to avoid it. So, I would like to add this feature, hopefully, it could help others like me.
What I do is add a placeholder(%sapper.assetsPrefix%) to get_page_hanlder.ts where generate js/css and HTTP links header, then when user run build or dev, it will read publicPath from webpack.config.js and replace it. So, the finally generated server runtime(server.mjs) could have a user-specified assets prefix. Because it needs to run build for every different publicPath, I add three subfolders in assets-prefix-webpack folder to test these three different situations. Looks weird, I know 😓.
So, for webpack users, all need to do is add a publicPath in their webpack.config.js like below.
Note that
client/
is not omitable.