-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular.webpack.js
More file actions
46 lines (37 loc) · 1.49 KB
/
angular.webpack.js
File metadata and controls
46 lines (37 loc) · 1.49 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
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = (config, options) => {
// Default to 'web' - safe for browser/Cypress environments
config.target = 'web';
if (options.fileReplacements) {
for (let fileReplacement of options.fileReplacements) {
if (fileReplacement.replace !== 'src/environments/environment.ts') {
continue;
}
let fileReplacementParts = fileReplacement['with'].split('.');
// environment.web.ts → parts: ['src/environments/environment', 'web', 'ts']
// environment.electron.ts → parts: ['src/environments/environment', 'electron', 'ts']
// environment.ts → parts: ['src/environments/environment', 'ts']
const envName = fileReplacementParts[fileReplacementParts.length - 2];
// Only switch to electron-renderer for explicit electron environments
if (['electron', 'electron-dev', 'electron-prod'].includes(envName)) {
config.target = 'electron-renderer';
} else {
config.target = 'web';
}
break;
}
}
// Only add NodePolyfillPlugin for web target — electron-renderer doesn't need polyfills
if (config.target === 'web') {
config.plugins = [
...config.plugins,
new NodePolyfillPlugin({
excludeAliases: ['console'],
}),
];
}
// Fix for karma-webpack globalObject issue
// https://github.com/ryanclark/karma-webpack/issues/497
config.output.globalObject = 'globalThis';
return config;
};