Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
split chunks plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pipopotamasu committed Nov 28, 2018
1 parent 996328c commit 4e83d66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/helpers/webpack_bundle_helper.rb
Expand Up @@ -9,6 +9,9 @@ def asset_bundle_path(entry, **options)
end

def javascript_bundle_tag(entry, **options)
# skip when not generate split chunk
return if entry == 'vendor' && !manifest.key?("#{entry}.js")

path = asset_bundle_path("#{entry}.js")

options = {
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -11,6 +11,7 @@

<body>
<%= yield %>
<%= javascript_bundle_tag 'vendor' %>
<%= yield :bundle_js %>
</body>
</html>
12 changes: 11 additions & 1 deletion webpack.config.js
Expand Up @@ -124,7 +124,17 @@ module.exports = {
]
},
optimization: {
minimizer: [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})]
minimizer: [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})],
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
name: "vendor",
chunks: "initial",
enforce: true
}
}
}
},
resolve: {
alias: {
Expand Down

0 comments on commit 4e83d66

Please sign in to comment.