-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
79 lines (77 loc) · 1.96 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
const path = require('path');
const ClosurePlugin = require('closure-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const stableLibraries = ['react', 'scheduler', 'react-dom', 'recoil', 'styled-components'];
const generalLibraries = ['marked', 'dompurify'];
module.exports = {
entry: './src/web/index.tsx',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.svg$/,
loader: 'url-loader'
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader',
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/html/index.html',
inject: true,
}),
new CopyPlugin({
patterns: [
{ from: './src/assets/', to: './assets/' },
],
}),
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
alias: {
'web': path.resolve(process.cwd(), './src/web/'),
}
},
optimization: {
minimizer: [
new ClosurePlugin({ mode: 'STANDARD' })
],
splitChunks: {
chunks: 'all',
cacheGroups: {
vendors: {
name: 'vendors',
test(module, chunks) {
return module.resource &&
module.resource.includes('node_modules') &&
stableLibraries.some(name => module.resource.includes(`/${name}/`));
}
},
libs: {
name: 'libaries',
test(module) {
return module.resource &&
module.resource.includes('node_modules') &&
generalLibraries.some(name => module.resource.includes(`/${name}/`));
}
},
}
}
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
},
};