-
Notifications
You must be signed in to change notification settings - Fork 4.4k
webpack 4, vue-loader 15, et al #1369
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
base: develop
Are you sure you want to change the base?
Changes from 37 commits
e98bcc0
6bba5e4
709b528
1c7856a
00aae83
edd85ff
27481de
f6f9cd9
c699f00
8d638f0
3ebf10b
00d5aa3
b2c2785
2056ba6
0783d37
3fc4965
e6cc3f2
63f95b3
df5dadf
d731f25
597f74a
cee65fd
6162c84
cd325ef
c503037
7ed7f28
6d13e1e
2d13661
0db5de0
052a757
b7a10c1
aac5cc0
3aa7005
882d316
7fe7b3c
3604040
ad1999d
31844ea
9bdb716
0e7e90c
922b68c
f43a379
26ea1fd
13904d2
3b24582
82b49a3
baead7a
7717e47
5b90c53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ const HOST = process.env.HOST | |
const PORT = process.env.PORT && Number(process.env.PORT) | ||
|
||
const devWebpackConfig = merge(baseWebpackConfig, { | ||
mode: 'development', | ||
module: { | ||
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) | ||
}, | ||
|
@@ -49,8 +50,6 @@ const devWebpackConfig = merge(baseWebpackConfig, { | |
'process.env': require('../config/dev.env') | ||
}), | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. | ||
new webpack.NoEmitOnErrorsPlugin(), | ||
// https://github.com/ampedandwired/html-webpack-plugin | ||
new HtmlWebpackPlugin({ | ||
filename: 'index.html', | ||
|
@@ -65,7 +64,11 @@ const devWebpackConfig = merge(baseWebpackConfig, { | |
ignore: ['.*'] | ||
} | ||
]) | ||
] | ||
], | ||
optimization: { | ||
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. This is not necessary. In the 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. You're right about However, the docs for |
||
namedModules: true, | ||
noEmitOnErrors: true, | ||
}, | ||
}) | ||
|
||
module.exports = new Promise((resolve, reject) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ const merge = require('webpack-merge') | |
const baseWebpackConfig = require('./webpack.base.conf') | ||
const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin') | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin') | ||
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') | ||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | ||
|
||
|
@@ -16,6 +16,7 @@ const env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing' | |
: {{/if_or}}require('../config/prod.env') | ||
|
||
const webpackConfig = merge(baseWebpackConfig, { | ||
mode: 'production', | ||
module: { | ||
rules: utils.styleLoaders({ | ||
sourceMap: config.build.productionSourceMap, | ||
|
@@ -27,30 +28,15 @@ const webpackConfig = merge(baseWebpackConfig, { | |
output: { | ||
path: config.build.assetsRoot, | ||
filename: utils.assetsPath('js/[name].[chunkhash].js'), | ||
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') | ||
}, | ||
plugins: [ | ||
// http://vuejs.github.io/vue-loader/en/workflow/production.html | ||
new webpack.DefinePlugin({ | ||
'process.env': env | ||
}), | ||
new UglifyJsPlugin({ | ||
uglifyOptions: { | ||
compress: { | ||
warnings: false | ||
} | ||
}, | ||
sourceMap: config.build.productionSourceMap, | ||
parallel: true | ||
}), | ||
// extract css into its own file | ||
new ExtractTextPlugin({ | ||
filename: utils.assetsPath('css/[name].[contenthash].css'), | ||
// Setting the following option to `false` will not extract CSS from codesplit chunks. | ||
// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. | ||
// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, | ||
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 | ||
allChunks: true, | ||
new MiniCssExtractPlugin({ | ||
filename: utils.assetsPath('css/[name].[chunkhash].css'), | ||
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. Better with |
||
}), | ||
// Compress extracted CSS. We are using this plugin so that possible | ||
// duplicated CSS from different components can be deduped. | ||
|
@@ -75,43 +61,12 @@ const webpackConfig = merge(baseWebpackConfig, { | |
// more options: | ||
// https://github.com/kangax/html-minifier#options-quick-reference | ||
}, | ||
// necessary to consistently work with multiple chunks via CommonsChunkPlugin | ||
// necessary to consistently work with multiple chunks | ||
chunksSortMode: 'dependency' | ||
}), | ||
// keep module.id stable when vendor modules does not change | ||
new webpack.NamedChunksPlugin(), | ||
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. https://webpack.js.org/guides/caching/#module-identifiers
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. @PanJiaChen Thanks for the thorough review! I did a lot of experimentation before I added the I found that almost every change I made to any It's definitely possible I missed something, or that the behavior improved since webpack 4.6 (it's now 4.16), but I hesitate to reopen this right now as changing this or upgrading to 4.16 might have further consequences. In any case, after this PR is approved, doing that kind of change is a much smaller and far more focused change. |
||
new webpack.HashedModuleIdsPlugin(), | ||
// enable scope hoisting | ||
new webpack.optimize.ModuleConcatenationPlugin(), | ||
// split vendor js into its own file | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'vendor', | ||
minChunks (module) { | ||
// any required modules inside node_modules are extracted to vendor | ||
return ( | ||
module.resource && | ||
/\.js$/.test(module.resource) && | ||
module.resource.indexOf( | ||
path.join(__dirname, '../node_modules') | ||
) === 0 | ||
) | ||
} | ||
}), | ||
// extract webpack runtime and module manifest to its own file in order to | ||
// prevent vendor hash from being updated whenever app bundle is updated | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'manifest', | ||
minChunks: Infinity | ||
}), | ||
// This instance extracts shared chunks from code splitted chunks and bundles them | ||
// in a separate chunk, similar to the vendor chunk | ||
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'app', | ||
async: 'vendor-async', | ||
children: true, | ||
minChunks: 3 | ||
}), | ||
|
||
// copy custom static assets | ||
new CopyWebpackPlugin([ | ||
{ | ||
|
@@ -120,7 +75,32 @@ const webpackConfig = merge(baseWebpackConfig, { | |
ignore: ['.*'] | ||
} | ||
]) | ||
] | ||
], | ||
optimization: { | ||
concatenateModules: true, | ||
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. In 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. 👍 |
||
splitChunks: { | ||
chunks: 'all', | ||
cacheGroups: { | ||
vendor: { | ||
name: 'vendor', | ||
test: /[\\/]node_modules[\\/]/, | ||
enforce: true, | ||
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 can't find any documentation on this enforce option? 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. @zevdg Quoting @thatisuday (webpack/webpack#6647 (comment)):
If I recall correctly, I added it to ensure consistent hashing, but I really don't remember the details and, in hindsight, that probably doesn't make much sense :(. I do remember that it took me way too long to solve whatever the problem was because, as you said, there was no documentation for The SplitChunksPlugin code basically uses it to arbitrarily set other parameters to default values that guarantee that the chunk will be created. |
||
}, | ||
}, | ||
}, | ||
runtimeChunk: 'single', | ||
minimizer: [ | ||
new UglifyJsPlugin({ | ||
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. Is this needed since you are already using According to the docs, they have removed |
||
uglifyOptions: { | ||
compress: { | ||
warnings: false | ||
} | ||
}, | ||
sourceMap: config.build.productionSourceMap, | ||
parallel: true | ||
}), | ||
], | ||
}, | ||
}) | ||
|
||
if (config.build.productionGzip) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
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.
Hi! Does this file still makes sense? vue-loader config was weird enough to justify its own file, but since now most of its configuration is wiped, should we consider inlining it to
webpack.base.conf.js
?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.
@gkatsanos, they seem to work well on my machine... The CSS file in
dist
is minified and when I click a selector, Chrome opens the.vue
file and highlights the proper line.Can you point me to something specific so I can verify?
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.
@afontcu, I think it should stay, but I'm not really sure.
Vue is very new for me, so I don't know how every setting affects the build or the app. I only made changes I felt certain were equivalent to the previous behavior or completely redundant, mainly by following Vue's migration guide, reading docs, and trial and error.
For example, I got rid of the
loaders
property because the new vue-loader explicitly deprecates it in favor of the the webpack loaders configuration. And I renamed thetransformToRequire
property totransformAssetUrls
, based on the guide.My hunch is that it should probably stay for the sake of clarity, even though the usage has changed a bit.
Having said that, I haven't checked if the
cacheBusting
property is used anywhere, and I'm not sure if we should add other properties that are relevant for the new vue-loader.