-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
95 lines (92 loc) · 1.88 KB
/
webpack.common.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
var webpack = require('webpack');
var path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isRelease = process.env.NODE_ENV === 'production';
const cssBundler = isRelease ? MiniCssExtractPlugin.loader : "style-loader";
const cssLoaders = [
cssBundler,
"css-modules-typescript-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: {
exportLocalsConvention: "camelCaseOnly",
localIdentName: "[name]---[local]",
},
}
},
];
module.exports = {
context: path.resolve(__dirname, 'site'),
entry: [
path.resolve(__dirname, 'site/index.tsx')
],
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
publicPath: '/',
}),
].concat(
isRelease ? [
new MiniCssExtractPlugin({
filename: "[name].css",
})
] : []
),
module: {
rules: [
{
test: /\.(gif|html|jpeg|jpg|png|svg|ttf|txt)$/i,
type: "asset/resource",
exclude: [
path.resolve(__dirname, "site/index.html"),
],
},
{
test: /\.tsx?$/,
use: ["babel-loader", "ts-loader"],
exclude: /node_modules/,
},
{
enforce: "pre",
test: "/\.js$/i",
loader: "source-map-loader"
},
{
test: /\.css$/i,
use: cssLoaders,
exclude: [
path.resolve(__dirname, "site/reset.css"),
]
},
{
test: path.resolve(__dirname, "site/reset.css"),
use: [cssBundler, "css-loader"]
}
]
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
output: {
path: path.resolve(__dirname, 'site/dist'),
filename: '[name].[contenthash].js',
assetModuleFilename: '[path][name][ext]',
clean: true,
},
optimization: {
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
};