-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.mjs
127 lines (109 loc) · 3.17 KB
/
webpack.config.mjs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import defaultConfig from '@wordpress/scripts/config/webpack.config.js';
import clone from 'deep-clone';
import {config} from 'dotenv';
import MiniCSSExtractPlugin from 'mini-css-extract-plugin';
import path from 'path';
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
config();
const createConfig = ({name, entry, dir, externals}) => {
const isProduction = process.env.NODE_ENV === 'production';
const config = {
...clone(defaultConfig),
name,
entry,
context: path.resolve(__dirname, dir),
module: {
...defaultConfig.module,
rules: [
{
resourceQuery: /inline/,
test: /\.(bmp|png|jpe?g|gif)$/i,
type: 'asset/inline',
},
{
test: /\.md$/i,
type: 'asset/source',
},
...defaultConfig.module.rules,
],
},
watchOptions: {
aggregateTimeout: 200,
poll: 1000,
},
resolveLoader: {
modules: [
path.resolve(__dirname, dir, 'node_modules'),
path.resolve(__dirname, dir, './'),
path.resolve(__dirname, 'node_modules'),
path.resolve(__dirname, 'scripts'),
],
},
stats: {
children: false,
all: false,
entrypoints: true,
warnings: true,
errors: true,
hash: false,
timings: true,
errorDetails: true,
builtAt: true,
},
experiments: {
topLevelAwait: true,
},
resolve: {
...defaultConfig.resolve,
extensions: ['.tsx', '.ts', '.js', '.jsx', '.json'],
alias: {
...defaultConfig.resolve.alias,
},
},
optimization: {
...defaultConfig.optimization,
removeEmptyChunks: true,
},
externals: {
...defaultConfig.externals,
...(externals || {}),
},
output: {
...defaultConfig.output,
filename: '[name].js',
path: path.resolve(__dirname, dir, 'build'),
},
plugins: [
new MiniCSSExtractPlugin({filename: '[name].css'}),
...defaultConfig.plugins.filter(
(plugin) => !['LiveReloadPlugin'].includes(plugin.constructor.name)
),
],
};
if (!isProduction) {
config.devServer.host = '127.0.0.1';
config.devServer.allowedHosts = 'all';
config.devServer.server = {
type: 'https',
options: {
key: process.env['TSL_KEY'],
cert: process.env['TSL_CERT'],
requestCert: false,
},
};
} else {
delete config.devServer;
}
return config;
};
export default [
createConfig({
name: 'settings',
dir: './',
entry: {
settings: './src/settings.tsx',
},
}),
];