fix(webpack): don't use hashes when watching

helps preventing memory leaks on dev mode and more clear source
This commit is contained in:
Pooya Parsa 2017-12-11 23:37:11 +03:30
parent f99897376b
commit b86426aaa0
3 changed files with 17 additions and 5 deletions

View File

@ -204,6 +204,18 @@ export default class Builder {
return options
}
getFileName(name) {
let fileName = this.options.build.filenames[name]
// Don't use hashes when watching
// https://github.com/webpack/webpack/issues/1914#issuecomment-174171709
if (this.options.dev) {
fileName = fileName.replace(/\[(chunkhash|contenthash|hash)\]\./g, '')
}
return fileName
}
async generateRoutesAndFiles() {
debug('Generating files...')
// -- Templates --

View File

@ -25,8 +25,8 @@ export default function webpackBaseConfig({ name, isServer }) {
},
output: {
path: resolve(this.options.buildDir, 'dist'),
filename: this.options.build.filenames.app,
chunkFilename: this.options.build.filenames.chunk,
filename: this.getFileName('app'),
chunkFilename: this.getFileName('chunk'),
publicPath: (isUrl(this.options.build.publicPath)
? this.options.build.publicPath
: urlJoin(this.options.router.base, this.options.build.publicPath))
@ -118,7 +118,7 @@ export default function webpackBaseConfig({ name, isServer }) {
const extractCSS = this.options.build.extractCSS
if (extractCSS) {
const extractOptions = Object.assign(
{ filename: this.options.build.filenames.css },
{ filename: this.getFileName('css') },
typeof extractCSS === 'object' ? extractCSS : {}
)
config.plugins.push(new ExtractTextPlugin(extractOptions))

View File

@ -73,7 +73,7 @@ export default function webpackClientConfig() {
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity,
filename: this.options.build.filenames.manifest
filename: this.getFileName('manifest')
})
)
@ -200,7 +200,7 @@ function commonChunksPlugin(config) {
config.plugins.unshift(
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: this.options.build.filenames.vendor,
filename: this.getFileName('vendor'),
minChunks(module, count) {
// Detect and externalize well-known vendor if detected
if (module.context && maybeVendor.some(v => module.context.includes(v))) {