Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
161 lines (156 loc) · 5.05 KB
/
Copy pathwebpack.config.js
File metadata and controls
161 lines (156 loc) · 5.05 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
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
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const { RawSource } = require( 'webpack-sources' );
const path = require( 'path' );
// Allow disabling minification via environment variable for easier debugging
// By default, minification is disabled for easier debugging
// Set MINIFY=true to enable minification for production builds
const shouldMinify = process.env.MINIFY === 'true';
// Plugin to remove source map references from node_modules
class RemoveSourceMapPlugin {
apply( compiler ) {
compiler.hooks.compilation.tap(
'RemoveSourceMapPlugin',
( compilation ) => {
// Use processAssets hook instead of emit to avoid deprecation warning
// PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE is the appropriate stage for modifying assets
compilation.hooks.processAssets.tap(
{
name: 'RemoveSourceMapPlugin',
stage: compilation.constructor
.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
},
() => {
// Process all chunks
compilation.chunks.forEach( ( chunk ) => {
chunk.files.forEach( ( filename ) => {
// Only process JS files
if ( filename.endsWith( '.js' ) ) {
const asset =
compilation.getAsset( filename );
if ( asset ) {
// Get source as string (handles both Source objects and strings)
const sourceObj = asset.source;
let source =
typeof sourceObj === 'string'
? sourceObj
: sourceObj.source();
// Remove source map references from node_modules code
// This regex matches //# sourceMappingURL=...map at the end of lines
source = source.replace(
/\/\/# sourceMappingURL=[^\n]*\.map$/gm,
''
);
// Update asset using the new API with proper Source object
compilation.updateAsset(
filename,
new RawSource( source )
);
}
}
} );
} );
}
);
}
);
}
}
module.exports = {
...defaultConfig,
entry: {
'admin-settings': './assets/src/admin-settings/index.js',
'admin-bar-export': './assets/src/admin-bar/index.js',
'export-modal': './assets/src/export-modal/index.js',
'provider-local-filesystem':
'./assets/src/providers/local-filesystem/index.js',
},
output: {
...defaultConfig.output,
path: require( 'path' ).resolve( __dirname, 'assets/build' ),
publicPath: '', // Will be set dynamically via __webpack_public_path__ in entry points
// Prevent webpack from creating chunk files - all code goes into entry bundles
// Setting chunkFilename to undefined ensures no chunk files are created
chunkFilename: undefined,
},
optimization: {
...defaultConfig.optimization,
minimize: shouldMinify,
// Completely disable code splitting - bundle everything into single files
// Setting splitChunks to false prevents webpack from creating any chunks
splitChunks: false,
// Disable runtime chunk (prevents webpack runtime from being split)
runtimeChunk: false,
// Use deterministic module IDs for consistent builds
moduleIds: 'deterministic',
},
performance: {
// Increase size limits for large bundles (publish.js is a complex feature)
// These bundles are acceptable for admin-only functionality
maxAssetSize: 500000, // 500 KiB
maxEntrypointSize: 500000, // 500 KiB
hints: 'warning', // Keep as warning to be aware of bundle sizes
},
module: {
...defaultConfig.module,
parser: {
...defaultConfig.module?.parser,
javascript: {
...defaultConfig.module?.parser?.javascript,
// Inline dynamic imports instead of creating separate chunk files
// This ensures ALL code is bundled into the entry file, no chunks created
dynamicImportMode: 'eager',
},
},
},
resolve: {
...defaultConfig.resolve,
alias: {
...defaultConfig.resolve?.alias,
// Path aliases for cleaner imports
'@altolith/utils': path.resolve( __dirname, 'assets/src/utils' ),
'@altolith/components': path.resolve(
__dirname,
'assets/src/components'
),
'@altolith/hooks': path.resolve( __dirname, 'assets/src/hooks' ),
'@altolith/constants': path.resolve(
__dirname,
'assets/src/constants'
),
'@altolith/contexts': path.resolve(
__dirname,
'assets/src/contexts'
),
'@altolith/services': path.resolve(
__dirname,
'assets/src/services'
),
'@altolith/providers': path.resolve(
__dirname,
'assets/src/providers'
),
'@altolith/export': path.resolve( __dirname, 'assets/src/export' ),
'@altolith/admin': path.resolve(
__dirname,
'assets/src/admin-settings'
),
'@altolith/profiles': path.resolve(
__dirname,
'assets/src/profiles'
),
},
fallback: {
...defaultConfig.resolve?.fallback,
// html-minifier-terser uses clean-css which requires Node.js modules
// Since we're not using CSS minification in html-minifier-terser (minifyCSS: false),
// we can safely ignore these modules
fs: false,
path: false,
url: false,
http: false,
https: false,
os: false,
},
},
plugins: [ ...defaultConfig.plugins, new RemoveSourceMapPlugin() ],
};