Skip to content

Commit 71a9a6e

Browse files
committed
Add hash name for build files in production mode
1 parent 0427b3f commit 71a9a6e

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

app/templates/_webpack.config.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
var webpack = require('webpack');
2-
var ExtractTextPlugin = require("extract-text-webpack-plugin");
2+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
33
var HtmlWepackPlugin = require('html-webpack-plugin');
44

55
// basic configurations
66
module.exports = {
7-
entry: './src/main.js',
7+
entry: {
8+
app: './src/main.js'
9+
},
810
output: {
911
path: './dist',
10-
publicPath: '/',
11-
filename: 'static/js/bundle.js'
12+
publicPath: '/'
1213
},
1314
resolve: {
1415
extensions: ['', '.js', '.vue']
@@ -54,21 +55,15 @@ module.exports = {
5455
}
5556
}
5657
]
57-
},
58-
vue: {
59-
loaders: {
60-
css: ExtractTextPlugin.extract('css'),
61-
less: ExtractTextPlugin.extract('css!less')
62-
}
63-
},
64-
plugins: [
65-
new ExtractTextPlugin("static/css/bundle.css")
66-
]
58+
}
6759
};
6860

6961
// production configurations
7062
if (process.env.NODE_ENV === 'production') {
71-
module.exports.plugins = module.exports.plugins.concat([
63+
module.exports.output.filename = 'static/js/[name]_[chunkhash].js';
64+
module.exports.output.chunkFilename = "static/js/[id]_[chunkhash].js";
65+
66+
module.exports.plugins = [
7267
new webpack.DefinePlugin({
7368
'process.env': {
7469
NODE_ENV: '"production"'
@@ -87,22 +82,33 @@ if (process.env.NODE_ENV === 'production') {
8782
removeComments: true,
8883
collapseWhitespace: true
8984
}
90-
})
91-
]);
85+
}),
86+
new ExtractTextPlugin('static/css/[name]_[contenthash].css')
87+
];
9288

93-
module.exports.vue.autoprefixer = {
94-
browsers: ['last 2 versions']
95-
}
89+
module.exports.vue = {
90+
autoprefixer: {
91+
browsers: ['last 2 versions']
92+
},
93+
loaders: {
94+
css: ExtractTextPlugin.extract('css'),
95+
less: ExtractTextPlugin.extract('css!less')
96+
}
97+
};
9698
} else {
9799
// development configurations
98-
module.exports.plugins = module.exports.plugins.concat([
100+
module.exports.output.filename = 'static/js/[name].js';
101+
102+
module.exports.plugins = [
99103
new HtmlWepackPlugin({
100104
filename: 'index.html',
101105
template: 'index.html'
102106
})
103-
]);
107+
];
108+
104109
module.exports.devServer = {
105110
contentBase: './dist'
106111
};
112+
107113
module.exports.devtool = '#source-map';
108114
}

0 commit comments

Comments
 (0)