-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwebpack.parts.js
114 lines (103 loc) · 2.87 KB
/
webpack.parts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* eslint-disable import/no-commonjs, line-comment-position */
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
exports.devServer = ({ host, port } = {}) => ({
devServer: {
// Enable history API fallback so HTML5 History API based
// routing works. Good for complex setups.
historyApiFallback: true,
// Display only errors to reduce the amount of output.
stats: 'errors-only',
// overlay: true is equivalent
overlay: {
errors: true,
warnings: true,
},
// Parse host and port from env to allow customization.
//
// If you use Docker, Vagrant or Cloud9, set
// host: options.host || '0.0.0.0';
//
// 0.0.0.0 is available to all network devices
// unlike default `localhost`.
host, // Defaults to `localhost`
port, // Defaults to 8080
},
});
exports.lintJavaScript = ({ include, exclude, options }) => ({
module: {
rules: [
{
test: /\.js$/,
// ensure that ESLint gets executed before anything else
include,
exclude,
enforce: 'pre',
loader: 'eslint-loader',
options,
},
],
},
});
exports.babelLoader = () => ({
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
});
exports.generateSourceMaps = ({ type }) => ({
devtool: type,
});
exports.minifyJavaScript = () => ({
optimization: {
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
cache: true,
parallel: 2,
uglifyOptions: {
mangle: true,
ie8: true,
keep_fnames: true, // eslint-disable-line
compress: {
drop_console: true,
},
},
}),
],
},
});
exports.bundleTreeChart = () => ({
plugins: [new BundleAnalyzerPlugin()],
});
exports.externals = () => ({
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
'prop-types': {
root: 'PropTypes',
commonjs2: 'prop-types',
commonjs: 'prop-types',
amd: 'prop-types',
},
});
exports.copy = (patterns, options) => ({
plugins: [new CopyWebpackPlugin([patterns], options)],
});