-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathwebpack.config.js
More file actions
78 lines (69 loc) · 2.32 KB
/
webpack.config.js
File metadata and controls
78 lines (69 loc) · 2.32 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
/**
* External dependencies
*/
const path = require('path');
const webpack = require('webpack');
/**
* WordPress dependencies
*/
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
/**
* Extend the @wordpress/scripts webpack config with custom settings
*/
module.exports = function (env, argv) {
const config = defaultConfig;
// Custom entry points
config.entry = {
app: path.join(__dirname, './src/react/index.js'),
amp: path.join(__dirname, './src/react/amp.js'),
admin: path.join(__dirname, './src/admin/index.js'),
};
// Custom output settings
config.output = {
...config.output,
path: path.join(__dirname, './build'),
filename: '[name].js',
chunkFilename: '[name].bundle.js',
// Custom chunkLoadingGlobal to avoid conflicts
chunkLoadingGlobal: 'wpJsonpLiveBlog',
// Use 'auto' to determine publicPath at runtime from document.currentScript
// This is required for React.lazy() dynamic imports to work correctly
publicPath: 'auto',
};
// Enable source maps for better debugging
config.devtool = 'source-map';
// Configure sass-loader to suppress @import deprecation warnings
// We'll migrate to @use in a future PR when we can properly refactor all SCSS
const configureSassLoader = (rule) => {
if (Array.isArray(rule.use)) {
rule.use.forEach((loader) => {
if (loader && typeof loader === 'object' &&
(loader.loader?.includes('sass-loader') || loader.loader?.includes('sass'))) {
if (!loader.options) loader.options = {};
if (!loader.options.sassOptions) loader.options.sassOptions = {};
loader.options.sassOptions.quietDeps = true;
loader.options.sassOptions.silenceDeprecations = ['import', 'global-builtin', 'color-functions'];
}
});
}
if (rule.oneOf) {
rule.oneOf.forEach(configureSassLoader);
}
};
config.module.rules.forEach(configureSassLoader);
// Add custom plugins
config.plugins.push(
// Global vars for checking dev environment
new webpack.DefinePlugin({
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'),
__PROD__: JSON.stringify(process.env.NODE_ENV === 'production'),
__TEST__: JSON.stringify(process.env.NODE_ENV === 'test'),
}),
// Ignore moment locales to reduce bundle size
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
})
);
return config;
};