-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient-config.js
More file actions
200 lines (185 loc) · 5.29 KB
/
Copy pathclient-config.js
File metadata and controls
200 lines (185 loc) · 5.29 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
const productionMode = 'production';
const developmentMode = 'development';
module.exports = ({ name, version }, rootPath, mode, entry, destination) => {
const config = {
mode,
// Capture a "profile" of the application, including statistics and hints, which can then be dissected using the Analyze tool.
// Use the StatsPlugin for more control over the generated profile.
profile: mode === developmentMode,
entry: {
app: path.resolve(rootPath, entry)
},
output: {
chunkFilename: `${name}.ui.[name].${version}.js`,
filename: `${name}.ui.${version}.js`,
path: path.join(rootPath, destination),
publicPath: '/app/'
},
resolve: {
extensions: [ '.json', '.js', '.jsx' ],
fallback: {
fs: false,
},
},
// Load all modules.
module: {
rules: [
{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [
[ '@babel/preset-env', {
targets: {
browsers: [ 'last 2 versions' ]
},
shippedProposals: true
} ],
'@babel/preset-react'
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from',
['@babel/plugin-transform-runtime', {
helpers: false,
regenerator: true
}],
'@babel/plugin-syntax-dynamic-import'
],
ignore: [ './node_modules/**/*.js' ]
}
},
exclude: path.join(rootPath, 'node_modules/')
},
{
test: /\.(png|ttf|svg|jpg|gif)/,
use: {
loader: 'url-loader?limit=8192'
}
},
{
test: /\.(woff|woff2|eot)/,
use: {
loader: 'url-loader?limit=100000'
}
},
{
test: /\.css$/,
use: [
(mode === developmentMode ? 'style-loader' : MiniCssExtractPlugin.loader),
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('postcss-simple-vars')(),
require('postcss-focus')(),
require('autoprefixer')({
overrideBrowserslist: [ 'last 2 versions', 'IE > 8' ]
}),
require('postcss-reporter')({
clearMessages: true
})
]
}
}
}
]
}
]
},
plugins: [
new webpack.ProvidePlugin({
React: 'react'
}),
new webpack.DefinePlugin({
__DEV__: JSON.stringify(mode === developmentMode),
'process.env': {
BROWSER: JSON.stringify(true),
NODE_ENV: JSON.stringify(mode)
},
__CLIENT__: JSON.stringify(true),
__SERVER__: JSON.stringify(false)
})
],
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/].*\.js$/, // we don't want css to be splitted
chunks: 'all',
name: 'vendors',
priority: 10,
enforce: true,
filename: `${name}.ui.vendors.${version}.js`
}
}
}
}
};
const extractCSS = () => {
config.plugins.push(
new MiniCssExtractPlugin({
filename: `${name}.ui.${version}.css`,
})
);
};
switch (mode) {
case productionMode:
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
compress: {
sequences: true,
dead_code: true,
conditionals: false,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
},
mangle: true,
format: {
comments: false
}
},
extractComments: true
})
];
config.plugins.push(
new StatsWriterPlugin({
filename: 'manifest.json',
transform: function transformData(data) {
const chunks = {
style: data.assetsByChunkName.app[0],
app: data.assetsByChunkName.app[1],
vendors: data.assetsByChunkName.vendors
};
return JSON.stringify(chunks);
}
})
);
extractCSS();
break;
case developmentMode:
default:
config.optimization = {};
config.output = {
path: path.join(rootPath, destination),
filename: 'bundle.js',
publicPath: 'http://localhost:3000/app/'
};
break;
}
return config;
};