-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
107 lines (104 loc) · 3.48 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as path from "path";
import {fileURLToPath} from 'url';
import * as HtmlWebpackPlugin from "html-webpack-plugin";
import webpack from "webpack";
import TerserPlugin from "terser-webpack-plugin";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const outputFileName = `[name]${process.env.NODE_ENV=="production"?"-[chunkhash]":""}.js`;
export default {
entry: './src/public/index.tsx',
output: {
path: path.resolve(__dirname, 'dist/public/assets'),
filename: outputFileName,
chunkFilename: outputFileName,
publicPath: '/'
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
splitChunks: {
cacheGroups: {
react: {
test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom)[\\/]/,
name: "react",
chunks: 'all',
},
luxon: {
test: /[\\/]node_modules[\\/](luxon)[\\/]/,
name: "luxon",
chunks: 'all'
},
vendor: {
test: /^(?=.*?\bnode_modules\b)((?!(react|react-dom|react-router|react-router-dom|luxon)).)*$/,
name: "vendor",
chunks: 'all'
}
}
},
},
resolve: {
extensions: ['.js', '.tsx', '.css', '.svg', '.png', '.ico']
},
devtool: `${process.env.NODE_ENV!=="production"?"inline-":""}source-map`,
module: {
rules: [
{
test: /\.tsx$/,
loader: "ts-loader"
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: {
mode: "local",
auto: ()=>true,
localIdentName: `${process.env.NODE_ENV!="development"?"[hash:base64:5]":"[local]--[hash:base64:5]"}`,
},
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[ 'autoprefixer', {}, ],
],
},
}
}
]
},
{
test: /\.(svg|png|jpeg|gif|ico)$/,
loader: 'url-loader',
options: {
limit: 8192,
context: "src/public/assets",
name: "[path][name].[ext]",
publicPath: "/"
}
}
]
},
plugins: [
new HtmlWebpackPlugin.default({
template: __dirname + '/src/public/index.html',
filename: '../index.html',
inject: 'head',
publicPath: '/'
}),
new webpack.optimize.AggressiveMergingPlugin()
]
};