webpack-rails
webpack-rails copied to clipboard
Support for multiple chunks
It looks like this gem breaks when using multiple chunks.
The fix seems to be to change Webpack::Rails::Manifest.asset_paths to the following implenentation —
def asset_paths(source)
raise WebpackError, manifest["errors"] unless manifest_bundled?
if manifest["entrypoints"][source] && paths = manifest["entrypoints"][source]['assets']
# # Can be either a string or an array of strings.
# # Do not include source maps as they are not javascript
[paths].flatten.reject { |p| p =~ /.*\.map$/ }.map do |p|
"/#{::Rails.configuration.webpack.public_path}/#{p}"
end
else
raise EntryPointMissingError, "Can't find entry point '#{source}' in webpack manifest"
end
end
Huh. Could have sworn we supported multiple chunks. Thanks for the issue.
Can you please submit this in a pull request?
I'm not sure if this will break webpack 1.x compatibility in any way...
Based on this spec, it looks like the manifest.json is supposed to look like —
{
"errors": [],
"assetsByChunkName": {
"entry1": [ "entry1.js", "entry1-a.js" ],
"entry2": "entry2.js"
}
}
However the actual manifest.json on my project looks like. Note that assetsByChunkName is not an array.
{
"assetsByChunkName": {
"single_page_apps/agents": "single_page_apps/agents-e7560caa94a75cbca3b1.js",
"vendor-and-helpers.chunk": "vendor-and-helpers.chunk-22b0993852189b6bf4ca.js"
},
"assets": [
{
"name": "single_page_apps/agents-e7560caa94a75cbca3b1.js",
"chunkNames": [
"single_page_apps/agents"
]
},
],
"entrypoints": {
"single_page_apps/agents": {
"assets": [
"vendor-and-helpers.chunk-22b0993852189b6bf4ca.js",
"single_page_apps/agents-e7560caa94a75cbca3b1.js"
]
}
}
}
@mipearson — may I get some thoughts on my comment above?