forked from britecharts/britecharts-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.parts.js
128 lines (117 loc) · 3.15 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-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 = () => ({
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
beautify: false,
comments: false,
mangle: {
'screw_ie8': true,
'keep_fnames': true,
},
parallel: {
cache: true,
workers: 2,
},
compress: {
'screw_ie8': true,
'properties': true,
'drop_debugger': true,
'dead_code': true,
'conditionals': true,
'booleans': true,
'unused': true,
'if_return': true,
'join_vars': true,
'drop_console': true,
'warnings': false,
},
}),
],
});
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),
],
});