-
Notifications
You must be signed in to change notification settings - Fork 3
/
angular.webpack.js
103 lines (95 loc) · 2.71 KB
/
angular.webpack.js
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
const arch = process.env.ARCH || process.arch;
const platform = process.env.PLATFORM || process.platform;
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');
module.exports = (config, options) => {
config.target = 'electron-renderer';
if (options.customWebpackConfig.target) {
config.target = options.customWebpackConfig.target;
} else if (options.fileReplacements) {
for (let fileReplacement of options.fileReplacements) {
if (fileReplacement.replace !== 'main_renderer/environments/environment.ts') {
continue;
}
let fileReplacementParts = fileReplacement['with'].split('.');
if (['dev', 'prod', 'test', 'electron-renderer'].indexOf(fileReplacementParts[1]) < 0) {
config.target = fileReplacementParts[1];
}
break;
}
}
config.externals = {
...config.externals,
electron: 'require(\'electron\')',
buffer: 'require(\'buffer\')',
child_process: 'require(\'child_process\')',
worker_threads: 'require(\'worker_threads\')',
crypto: 'require(\'crypto\')',
dialog: 'require(\'dialog\')',
events: 'require(\'events\')',
fs: 'require(\'fs\')',
http: 'require(\'http\')',
https: 'require(\'https\')',
assert: 'require(\'assert\')',
dns: 'require(\'dns\')',
net: 'require(\'net\')',
os: 'require(\'os\')',
path: 'require(\'path\')',
querystring: 'require(\'querystring\')',
readline: 'require(\'readline\')',
repl: 'require(\'repl\')',
stream: 'require(\'stream\')',
string_decoder: 'require(\'string_decoder\')',
url: 'require(\'url\')',
util: 'require(\'util\')',
zlib: 'require(\'zlib\')',
'electron-is-dev': 'require(\'electron-is-dev\')'
};
config.module.rules = [
...config.module.rules,
{
test: /\.node$/,
use: 'node-loader'
}, {
test: /\.vert$/i,
use: 'raw-loader'
}, {
test: /\.frag$/i,
use: 'raw-loader'
}, {
test: /\.txt$/i,
use: 'raw-loader'
}, {
test: /\.svg$/i,
use: 'raw-loader'
}, {
test: /\.ya?ml$/i,
use: [{
loader: 'js-yaml-loader',
options: {
safe: false
}
}]
}
];
config.resolveLoader = {
alias: {
// Register loader so it can be used inline with import
'ttf-msdf-loader': require('path').resolve('./webpack_plugin/ttf-msdf-loader.js'),
},
};
config.plugins = [
...config.plugins,/*,
new BundleAnalyzerPlugin({
generateStatsFile: true
})*/
];
// Could be fun
/*config.optimization.minimizer.push(new TerserPlugin({
terserOptions: {
topLevel: true,
ecma: 6
}
}))*/
return config;
};