-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebpackHelpers.js
83 lines (76 loc) · 2.04 KB
/
webpackHelpers.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
import path from 'path';
import webpack from 'webpack';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
export const DEVELOPMENT_ENV = 'development';
export const PRODUCTION_ENV = 'production';
export const resolvePath = dir => path.resolve(__dirname, dir);
export const getDevTool = ({ mode }) => (mode === DEVELOPMENT_ENV ? 'cheap-module-eval-sourcemap' : 'source-map');
export const getStyleLoaders = ({ mode }) => {
if (mode === DEVELOPMENT_ENV) {
return ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'];
}
return [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'];
};
export const getEntry = ({ mode }) => {
if (mode === DEVELOPMENT_ENV) {
return [
'webpack-hot-middleware/client?reload=truepath=//localhost:4200/__webpack_hmr',
'./client/src/index.js'
];
}
return {
main: './client/src/index.js'
};
};
export const getEnvPlugins = ({ mode }) => {
if (mode === PRODUCTION_ENV) {
return [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(PRODUCTION_ENV)
}
})
];
}
// Excluding hot module in production fixes
// EventSource's response has a MIME type ('text/html')
// that is not 'text/event-stream'. Aborting the connection. error
return [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(DEVELOPMENT_ENV)
}
})
];
};
export const getFileName = ({ mode }) => {
if (mode === DEVELOPMENT_ENV) {
return '[name].[hash].js';
}
return '[name].[chunkhash].js';
};
export const getOptimisers = ({ mode }) => {
if (mode !== PRODUCTION_ENV) {
return {
optimization: {
minimize: false
}
};
}
return {
optimization: {
minimize: true,
runtimeChunk: false,
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
}
}
};
};