-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Update to webpack v5 #4054
Update to webpack v5 #4054
Changes from all commits
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 |
---|---|---|
@@ -1,30 +1,21 @@ | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin'); | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | ||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); | ||
const CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
|
||
module.exports = (env, options) => { | ||
const devMode = options.mode !== 'production'; | ||
|
||
return { | ||
optimization: { | ||
minimizer: [ | ||
new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }), | ||
new OptimizeCSSAssetsPlugin({}) | ||
] | ||
}, | ||
entry: { | ||
'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js']) | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
path: path.resolve(__dirname, '../priv/static/js'), | ||
filename: '[name].js', | ||
publicPath: '/js/' | ||
}, | ||
devtool: devMode ? 'eval-cheap-module-source-map' : undefined, | ||
module: { | ||
rules: [ | ||
{ | ||
|
@@ -45,9 +36,19 @@ module.exports = (env, options) => { | |
] | ||
}, | ||
plugins: [ | ||
new MiniCssExtractPlugin({ filename: '../css/[name].css' }), | ||
new CopyWebpackPlugin([{ from: 'static/', to: '../' }]) | ||
] | ||
.concat(devMode ? [new HardSourceWebpackPlugin()] : []) | ||
new MiniCssExtractPlugin({ filename: '../css/app.css' }), | ||
new CopyWebpackPlugin({ | ||
patterns: [ | ||
{ from: 'static/', to: '../' } | ||
] | ||
}) | ||
], | ||
optimization: { | ||
minimizer: [ | ||
'...', | ||
cw789 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new CssMinimizerPlugin() | ||
] | ||
}, | ||
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. I also think you will get compilation errors if you don't specify 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. That's a thing I for myself would need to explore more in detail. I didn't get the consequences of this now. 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. I thought the same too but when I deployed with |
||
devtool: devMode ? 'source-map' : undefined | ||
} | ||
}; |
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.
Hey so I did my own webpack upgrade and I think you'll need a few other rules to ensure the most compatibility:
This comes directly from the Webpack 5 tutorial to ensure fonts and images are loaded successfully as well
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 also noticed once that this is needed if you want to process assets by webpack.
But then I didn't touch any of these anymore.
It was not clear for me which file types people really need to have in 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.
makes sense - i think it's pretty safe to say that in general css, js, images, and fonts are all fair game