-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
93 lines (83 loc) · 2.08 KB
/
webpack.config.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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const WEBPACK_SERVER_PORT = process.env.WEBPACK_SERVER_PORT || 5001;
const webpackConfig = (env, argv) => {
const { mode } = argv;
const production = mode === 'production';
const development = !production;
const analyze = false;
const plugins = [new HtmlWebpackPlugin({ template: 'src/index.html.ejs' })];
if (analyze) {
plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle_report.html',
}),
);
}
return {
entry: './src/index.tsx',
output: {
filename: '[name].[contenthash].bundle.js',
publicPath: '/',
},
devtool: 'source-map',
devServer: {
allowedHosts: 'all',
hot: true,
host: 'localhost',
historyApiFallback: true,
port: WEBPACK_SERVER_PORT,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
plugins,
optimization: {
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /\/node_modules\//,
name: 'vendors',
chunks: 'all',
},
},
},
},
module: {
rules: [
{ test: /\.tsx?$/, loader: 'ts-loader' },
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
'resolve-url-loader',
'sass-loader?sourceMap',
],
},
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader' },
],
},
};
};
module.exports = webpackConfig;