-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.mjs
169 lines (154 loc) · 3.79 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import TerserPlugin from 'terser-webpack-plugin';
import ESLintPlugin from 'eslint-webpack-plugin';
import nodeExternals from 'webpack-node-externals';
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import buildLocales from './build-locales.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const date = new Date();
const dist = path.resolve(__dirname, 'dist');
buildLocales();
const ESLintOptions = {
configType: 'flat',
overrideConfigFile: './eslint.config.mjs',
};
const banner = `
${pkg.title} version ${pkg.version} (${date.toISOString().substring(0, 10)})
${pkg.description}
${pkg.homepage}
(c) 2000-${date.getFullYear()} ${pkg.author.name || pkg.author}
Licensed under the EUPL, Version 1.2 or -as soon they will be approved by
the European Commission- subsequent versions of the EUPL (the "Licence");
You may not use this work except in compliance with the Licence.
You may obtain a copy of the Licence at:
https://joinup.ec.europa.eu/software/page/eupl
Unless required by applicable law or agreed to in writing, software
distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Licence for the specific language governing permissions and limitations
under the Licence.
For full license information of included components please see: jclic.components.LICENSE
WARNING: This is a compressed version of ${pkg.title}. Full source code is freely available at:
${pkg.homepage}
`;
/**
* Inline assets as raw text or Base64 URIs
* See: https://webpack.js.org/guides/asset-modules/
*/
const assetRules = [
{
test: /\.css$/,
type: 'asset/source',
},
{
test: /\.svg$/,
type: 'asset/source',
},
{
test: /\.png$/,
type: 'asset/inline',
},
{
test: /\.mp3$/,
type: 'asset/inline',
},
];
/**
* Bundle used in HTML browsers
*/
const mainConfig = {
// Override when debugging with: `webpack --mode=development`
// See: https://webpack.js.org/configuration/mode/
mode: 'production',
entry: './src/JClic.js',
devtool: 'source-map',
output: {
path: dist,
filename: 'jclic.min.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
],
}
},
},
...assetRules,
]
},
devServer: {
host: 'localhost',
port: 9001,
open: true,
static: {
directory: path.join(__dirname, 'test'),
watch: true,
},
client: {
overlay: true,
progress: true,
},
},
performance: {
maxAssetSize: 2000000,
maxEntrypointSize: 2000000,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
extractComments: {
filename: 'jclic.components.LICENSE',
banner: () => banner,
},
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
}
}),
],
},
plugins: [
new ESLintPlugin(ESLintOptions),
],
resolve: {
fallback: { stream: false }
},
};
/**
* Bundle used by Node.js apps
*/
const nodeConfig = {
target: 'node',
mode: 'production',
externals: [nodeExternals()],
entry: './src/jclic-node.js',
module: {
rules: [...assetRules],
},
devtool: 'source-map',
output: {
path: dist,
filename: 'jclic-node.js',
library: {
type: 'commonjs2',
export: 'default',
},
},
optimization: {
minimize: false,
},
plugins: [
new ESLintPlugin(ESLintOptions),
],
};
export default [mainConfig, nodeConfig];