Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
86 lines (83 loc) · 2.36 KB
/
Copy pathwebpack.config.js
File metadata and controls
86 lines (83 loc) · 2.36 KB
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 path = require('path');
const pkg = require('./package.json');
const webpack = require('webpack');
const frontendDir = path.resolve(__dirname, 'custom_components/voice_satellite/frontend');
const baseConfig = {
entry: {
'voice-satellite-card': './src/index.js',
'voice-satellite-panel': './src/panel/index.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
type: 'asset/source',
},
],
},
plugins: [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(pkg.version),
}),
],
// Dynamic import() chunks (e.g. wake-word, skins) are loaded from the
// same static path as the main card JS (/voice_satellite/). Keep
// physical filenames stable because HACS does not remove old files on
// update.
output: {
publicPath: '/voice_satellite/',
clean: {
keep: /^(fonts|vendor)\//,
},
},
// Pin chunk names to the file path (e.g. src_wake-word_worker_inference-worker_js)
// in BOTH dev and prod. Webpack defaults to 'named' in dev and 'deterministic'
// (numeric like '803') in prod, which produces different chunk URLs between
// the two modes. A user who locally ran `npm run dev` and then upgraded to a
// production release would have the dev bundle's chunk URLs cached and get
// 404s for chunks that the prod bundle renamed. Keeping the names stable
// also makes production chunks debuggable.
optimization: {
chunkIds: 'named',
},
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
// Dev: unminified with source maps (npm run dev)
return {
...baseConfig,
output: {
...baseConfig.output,
filename: '[name].js',
chunkFilename: `voice-satellite-[name].js?v=${pkg.version}`,
path: frontendDir,
},
optimization: {
...baseConfig.optimization,
minimize: false,
},
devtool: 'source-map',
};
}
// Production: minified, no source map (npm run build / CI)
return {
...baseConfig,
output: {
...baseConfig.output,
filename: '[name].js',
chunkFilename: `voice-satellite-[name].js?v=${pkg.version}`,
path: frontendDir,
},
optimization: {
...baseConfig.optimization,
minimize: true,
},
};
};