-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
86 lines (78 loc) · 2.32 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
const fs = require('fs');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const srcRoot = path.resolve(__dirname, 'src');
const symbols = /[\r\n%#()<>?[\\\]^`{|}]/g;
const xmlPrologue = /<\?xml.+?\?>[^\S]*/g;
const encodeSVG = (data, externalQuotesValue = 'double') => {
if (externalQuotesValue === 'double') {
data = data.replace(/"/g, `'`);
} else {
data = data.replace(/'/g, `"`);
}
data = data.replace(xmlPrologue, ``);
data = data.replace(/>\s{1,}</g, `><`);
data = data.replace(/\s{2,}/g, ` `);
return data.replace(symbols, encodeURIComponent);
};
const svgToDataURI = (data, mimeType = 'image/svg+xml') => `data:${mimeType},${encodeSVG(data)}`;
module.exports = {
entry: ['index', 'html/styles/style.css'],
output: {
clean: true,
filename: 'js/[name].[contenthash:6].js',
},
resolve: {
modules: [srcRoot, 'node_modules'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
symlinks: false,
},
module: {
rules: [
{
test: /\.css$/i,
include: srcRoot,
use: ['css-loader'],
},
{
test: /((?<!\.d)\.ts|\.tsx|\.js|\.jsx)$/,
include: srcRoot,
use: [
'thread-loader',
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
],
},
{
enforce: 'pre',
test: /\.js$/,
include: srcRoot,
loader: 'source-map-loader',
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'initial',
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
title: 'monotron',
template: 'src/html/index.ejs',
faviconDataUrl: svgToDataURI(
fs.readFileSync(path.resolve(__dirname, 'src/favicon.svg'), { encoding: 'utf-8' })
),
}),
],
};