-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix asset host support & improve output path #397
Conversation
And fix asset hosts
`config.action_controller.asset_host` won’t work when: * It’s a Proc * It’s nil (the application may set `ActionController::Base.asset_host` directly)
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.
Looking good
|
||
const output = { | ||
path: resolve('public', paths.output), | ||
publicPath: formatPublicPath(env.ASSET_HOST, paths.output) |
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.
How about we set ASSET_HOST
to dev server host in development when it's enabled? That way we don't need to replace manifest plugin.
if (env.NODE_ENV === "development") {
env.ASSET_HOST = `//${host}:${port}` // relative to origin
}
OR
if (env.NODE_ENV === "development") {
env.ASSET_HOST = `${devServer.https ? 'https': 'http'}://${devServer.host}:${devServer.port}`
}
We would be able to do this in development config without if
, but guess we can't since we have much shared logic here.
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.
I described the reason for not doing it this way in the PR:
Fixes that
webpacker:compile
andbin/webpack
would generate dev server URLs in development mode. This should only happen when usingbin/webpack-dev-server
.
That said, I cleaned things up in 2a94cdf by constructing and setting ASSET_HOST
in bin/webpack-dev-server
.
const publicPath = formatPublicPath(`http://${host}:${port}`, paths.output) | ||
|
||
// Remove ManifestPlugin so we can replace it with a new one | ||
devConfig.plugins = devConfig.plugins.filter(plugin => plugin.constructor.name !== 'ManifestPlugin') |
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.
If we consider using ASSET_HOST
env in development then I guess we don't need any of the changes here :)
default: &default # ~ = Rails.root | ||
source: app/javascript # ~/:source | ||
entry: packs # ~/:source/:entry | ||
output: packs # ~/public/:output |
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.
Awesome 👍 been thinking to do this
instance.data | ||
end | ||
|
||
def default_paths |
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.
🍰 🎉
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.
Looks good to me!
You guys are awesome! Thanks for working on this feature 👏 |
Fixes duplicated asset hosts (Fixes javascript_pack_tag seems to add path twice with asset host #320, Closes Fix asset host duplication #335)
Fixes that asset hosts would be ignored when defined as
Proc
or when set onActionController::Base.asset_host
directlyFixes that
webpacker:compile
andbin/webpack
would generate dev server URLs in development mode. This should only happen when usingbin/webpack-dev-server
.Changes
paths.output
so that it's:public/
paths.entry
paths.output/paths.entry
, but wouldn't includepaths.output
in generated URLs. So, if you changedpaths.output
, you'd end up with busted URLs:Before:
After: