Skip to content

Commit e5d8096

Browse files
committed
Optimize webpack.config
1 parent 27376cd commit e5d8096

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

webpack.config.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const pkg = require('./package.json');
1313
module.exports = ({production = false} = {}) => {
1414
process.env.NODE_ENV = production ? 'production' : 'development';
1515

16-
const path = resolve(__dirname, './build');
16+
const output = {
17+
path: resolve(__dirname, './build'),
18+
filename: production ? '[name].[chunkhash].js' : '[name].js',
19+
chunkFilename: production ? '[name].[chunkhash].js' : '[name].js'
20+
};
1721
const include = resolve(__dirname, './src');
18-
const filename = production ? '[name].[chunkhash].js' : '[name].js';
19-
const chunkFilename = filename;
2022
const sourceMap = production ? 'cheap-module-source-map' : false;
2123
const devtool = production ? 'cheap-module-source-map' : false;
2224

@@ -31,8 +33,6 @@ module.exports = ({production = false} = {}) => {
3133

3234
const transform = c => c.toString().replace(/FIREBASE_CONFIG/, defined.FIREBASE_CONFIG);
3335

34-
const minChunks = m => m.resource && m.resource.includes('node_modules');
35-
3636
const minify = production ? {
3737
removeComments: true,
3838
collapseWhitespace: true,
@@ -49,7 +49,7 @@ module.exports = ({production = false} = {}) => {
4949
main: ['./src/main.js'],
5050
vendor: ['react', 'react-dom', 'react-router', 'material-ui', 'firebase']
5151
},
52-
output: {path, filename, chunkFilename},
52+
output,
5353
module: {
5454
loaders: [{
5555
test: /\.(js|jsx)$/,
@@ -65,8 +65,8 @@ module.exports = ({production = false} = {}) => {
6565
plugins: [
6666
new optimize.CommonsChunkPlugin({
6767
name: 'vendor',
68-
filename,
69-
minChunks
68+
output: output.filename,
69+
minChunks: m => m.resource && m.resource.includes('node_modules')
7070
}),
7171
new optimize.CommonsChunkPlugin({
7272
name: 'manifest',
@@ -93,7 +93,7 @@ module.exports = ({production = false} = {}) => {
9393
cacheId: `${pkg.name}-${pkg.version}`,
9494
stripPrefix: './build',
9595
staticFileGlobs: [
96-
join(path, '**/*')
96+
join(output.path, '**/*')
9797
],
9898
runtimeCaching: [{
9999
urlPattern: /https:\/\/.+.firebaseio.com/,

0 commit comments

Comments
 (0)