Skip to content

Commit 9f92bba

Browse files
committed
Use webpack-merge.
Move html export config to own file. Delete unnecessary config options. Use cheap source maps. Signed-off-by: David Mehren <[email protected]>
1 parent 9a2dcd4 commit 9f92bba

File tree

5 files changed

+59
-111
lines changed

5 files changed

+59
-111
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
"url-loader": "^1.0.1",
189189
"webpack": "^4.14.0",
190190
"webpack-cli": "^3.1.0",
191+
"webpack-merge": "^4.1.4",
191192
"webpack-parallel-uglify-plugin": "^1.1.0"
192193
},
193194
"standard": {

webpack.common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var gracefulFs = require('graceful-fs')
1010
gracefulFs.gracefulify(fs)
1111

1212
module.exports = {
13+
name: 'app',
1314
plugins: [
1415
new webpack.ProvidePlugin({
1516
Visibility: 'visibilityjs',

webpack.dev.js

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
1-
var baseConfig = require('./webpack.common')
2-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
3-
var path = require('path')
1+
const common = require('./webpack.common.js')
2+
const htmlexport = require('./webpack.htmlexport')
3+
const merge = require('webpack-merge')
44

5-
module.exports = [Object.assign({}, baseConfig, {
6-
plugins: baseConfig.plugins.concat([
7-
new MiniCssExtractPlugin({
8-
filename: '[name].css',
9-
chunkFilename: '[id].css'
10-
})
11-
12-
]),
13-
devtool: 'source-map'
14-
}), {
15-
devtool: 'source-map',
16-
entry: {
17-
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
18-
},
19-
module: {
20-
rules: [{
21-
test: /\.css$/,
22-
use: ['style-loader', 'css-loader']
23-
}, {
24-
test: /\.scss$/,
25-
use: ['style-loader', 'sass-loader']
26-
}, {
27-
test: /\.less$/,
28-
use: ['style-loader', 'less-loader']
29-
}]
30-
},
31-
output: {
32-
path: path.join(__dirname, 'public/build'),
33-
publicPath: '/build/',
34-
filename: '[name].js'
35-
},
36-
plugins: [
37-
new MiniCssExtractPlugin({
38-
filename: 'html.min.css'
39-
})
40-
]
41-
}]
5+
module.exports = [
6+
// merge common config
7+
merge(common, {
8+
mode: 'development',
9+
devtool: 'cheap-module-eval-source-map'
10+
}),
11+
merge(htmlexport, {
12+
mode: 'development',
13+
devtool: 'cheap-module-eval-source-map'
14+
})]

webpack.htmlexport.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2+
const path = require('path')
3+
4+
module.exports = {
5+
name: 'save-as-html',
6+
entry: {
7+
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
8+
},
9+
module: {
10+
rules: [{
11+
test: /\.css$/,
12+
use: [MiniCssExtractPlugin.loader, 'css-loader']
13+
}]
14+
},
15+
output: {
16+
path: path.join(__dirname, 'public/build'),
17+
publicPath: '/build/',
18+
filename: '[name].js'
19+
},
20+
plugins: [
21+
new MiniCssExtractPlugin({
22+
filename: 'html.min.css'
23+
})
24+
]
25+
}

webpack.prod.js

Lines changed: 19 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,23 @@
1-
var baseConfig = require('./webpack.common')
2-
var webpack = require('webpack')
3-
var path = require('path')
1+
const common = require('./webpack.common.js')
2+
const htmlexport = require('./webpack.htmlexport')
3+
const merge = require('webpack-merge')
4+
const path = require('path')
45
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
5-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
6-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
76

8-
module.exports = [Object.assign({}, baseConfig, {
9-
plugins: baseConfig.plugins.concat([
10-
new webpack.DefinePlugin({
11-
'process.env': {
12-
'NODE_ENV': JSON.stringify('production')
13-
}
14-
})
15-
]),
16-
17-
optimization: {
18-
minimizer: [
19-
new UglifyJsPlugin({
20-
parallel: true,
21-
cache: true
22-
})
23-
],
24-
splitChunks: {
25-
chunks: 'async',
26-
minChunks: Infinity
7+
module.exports = [
8+
merge(common, {
9+
mode: 'production',
10+
output: {
11+
path: path.join(__dirname, 'public/build'),
12+
publicPath: '/build/',
13+
filename: '[name].[contenthash].js'
2714
}
28-
},
29-
30-
output: {
31-
path: path.join(__dirname, 'public/build'),
32-
publicPath: '/build/',
33-
filename: '[id].[name].[hash].js'
34-
// baseUrl: '<%- url %>'
35-
}
36-
}), {
37-
// This Chunk is used in the 'save as html' feature.
38-
// It is embedded in the html file and contains CSS for styling.
39-
40-
entry: {
41-
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
42-
},
43-
44-
output: {
45-
path: path.join(__dirname, 'public/build'),
46-
publicPath: '/build/',
47-
filename: '[name].js'
48-
},
49-
plugins: [
50-
new webpack.DefinePlugin({
51-
'process.env': {
52-
'NODE_ENV': JSON.stringify('production')
53-
}
54-
}),
55-
new MiniCssExtractPlugin({
56-
filename: 'html.min.css'
57-
})
58-
],
59-
60-
optimization: {
61-
minimizer: [
62-
new OptimizeCSSAssetsPlugin({})
63-
]
64-
},
65-
66-
module: {
67-
rules: [{
68-
test: /\.css$/,
69-
use: [
70-
MiniCssExtractPlugin.loader,
71-
'css-loader'
15+
}),
16+
merge(htmlexport, {
17+
mode: 'production',
18+
optimization: {
19+
minimizer: [
20+
new OptimizeCSSAssetsPlugin({})
7221
]
73-
}]
74-
}
75-
}]
22+
}
23+
})]

0 commit comments

Comments
 (0)