-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip CDN from manifest output #473
Changes from 3 commits
eb7d0ad
ee7e32c
3d5cc48
3e7ff83
cf41176
8001277
3fa49d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,32 @@ manager is used to manage JavaScript dependencies. | |||||||||||||||||
Support for Ruby 2.6 and Node v12 has also been dropped since they're very old | ||||||||||||||||||
at this point. | ||||||||||||||||||
|
||||||||||||||||||
## CDN host is stripped from the manifest output | ||||||||||||||||||
|
||||||||||||||||||
In Webpacker v5 the manifest.json file did not include the CDN asset host if defined. THis has been added in the aborted v6 and we've retained this in Shakapacker. | ||||||||||||||||||
justin808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
||||||||||||||||||
Presence of this host in the output could lead to unexpected issues and required [some workarounds](https://github.com/shakacode/shakapacker/blob/main/docs/troubleshooting.md#wrong-cdn-src-from-javascript_pack_tag) in certain cases. | ||||||||||||||||||
|
||||||||||||||||||
If you are not using CDN, then this change will have no effect on your setup. | ||||||||||||||||||
|
||||||||||||||||||
If you are using CDN and your CDN host is static, `config.asset_host` setting in Rails will be respected during compilation and when referencing assets through view helpers. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the missing article "the". - If you are using CDN and your CDN host is static, `config.asset_host` setting in Rails will be respected during compilation and when referencing assets through view helpers.
+ If you are using CDN and your CDN host is static, the `config.asset_host` setting in Rails will be respected during compilation and when referencing assets through view helpers. Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
If your host might differ, between various environments for example, you will either need to: | ||||||||||||||||||
- Ensure the assets are specifically rebuilt for each environment (Heroku pipeline promote feature for example does not do that by default). | ||||||||||||||||||
- Make sure the assets are compiled with `SHAKAPACKER_ASSET_HOST=''` ENV variable to avoid hardcording URLs in packs output. | ||||||||||||||||||
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure lists are surrounded by blank lines. - If your host might differ, between various environments for example, you will either need to:
- - Ensure the assets are specifically rebuilt for each environment (Heroku pipeline promote feature for example does not do that by default).
- - Make sure the assets are compiled with `SHAKAPACKER_ASSET_HOST=''` ENV variable to avoid hardcording URLs in packs output.
+ If your host might differ, between various environments for example, you will either need to:
+ - Ensure the assets are specifically rebuilt for each environment (Heroku pipeline promote feature for example does not do that by default).
+ - Make sure the assets are compiled with `SHAKAPACKER_ASSET_HOST=''` ENV variable to avoid hardcoding URLs in packs output. Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
Second option has got a certain gotcha - dynamic imports and static asset references (like image paths in CSS) will end up without host reference and the app will try and fetch them from your app host rather than defined `config.asset_host`. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the spelling of "hardcoding". - Make sure the assets are compiled with `SHAKAPACKER_ASSET_HOST=''` ENV variable to avoid hardcording URLs in packs output.
+ Make sure the assets are compiled with `SHAKAPACKER_ASSET_HOST=''` ENV variable to avoid hardcoding URLs in packs output. Committable suggestion
|
||||||||||||||||||
|
||||||||||||||||||
To get around that, you can use dynamic override as outlined by [Webpack documentation](https://webpack.js.org/guides/asset-modules/#on-the-fly-override). | ||||||||||||||||||
|
||||||||||||||||||
Setting for example: | ||||||||||||||||||
|
||||||||||||||||||
``` | ||||||||||||||||||
__webpack_public_path__ = 'https://mycdn.url.com/packs'; | ||||||||||||||||||
``` | ||||||||||||||||||
Comment on lines
+32
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify the language for the code block. - ```
+ ```javascript |
||||||||||||||||||
|
||||||||||||||||||
In your code and ensuring it is run first in the app, will allow the dynamic imports lookup path to be overriden at runtime. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the setting of an assets CDN during compilation is maybe a huge anti-pattern as it precludes using the same bundles on staging and production unless your assets are exactly the same and properly fingerprinted. Thoughts? Should this be mentioned? In other words, shouldn't the CDN be set via an ENV value and not put into the builds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's kinda what Webpack does though and usually mentions in their docs when CDN comes into play https://webpack.js.org/guides/public-path/#environment-based
You could probably do something like |
||||||||||||||||||
|
||||||||||||||||||
## The `packageManager` property in `package.json` is used to determine the package manager | ||||||||||||||||||
|
||||||||||||||||||
The biggest functional change in v8, `shakapacker` is now able to work with any | ||||||||||||||||||
justin808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ const getPlugins = () => { | |
writeToDisk: true, | ||
output: config.manifestPath, | ||
entrypointsUseAssets: true, | ||
publicPath: true | ||
publicPath: config.publicPathWithoutCDN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to document who this affects and the migration instructions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, I'll get something added to the migration guide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done? |
||
}) | ||
] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider simplifying "prior to" to "before" for clarity.
Committable suggestion