This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
forked from Thorn-Rose/pixel.horse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
89 lines (83 loc) · 3.21 KB
/
webpack.prod.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
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const WrapperPlugin = require('wrapper-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { AngularCompilerPlugin } = require('@ngtools/webpack');
const common = require('./webpack.common.js');
const config = require('./config.json');
const analytics = config.analytics ? `
(function(i, s, o, g, r, a, m) {i['GoogleAnalyticsObject']=r; i[r]=i[r]||function() {
(i[r].q=i[r].q||[]).push(arguments) }, i[r].l=1*new Date(); a=s.createElement(o),
m=s.getElementsByTagName(o)[0]; a.async=1; a.src=g; m.parentNode.insertBefore(a, m)
}) (window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', '${config.analytics.trackingID}', 'auto');
ga('send', 'pageview');
` : ``;
const compilerOptions = require('./tsconfig-aot.json').compilerOptions;
const compilerOptionsES = require('./tsconfig-aot-es.json').compilerOptions;
const scripts = [
['bootstrap', 'app/app.module#AppModule', 'assets', compilerOptions, 'tsconfig-aot.json', 5, false],
// ['bootstrap-es', 'app/app.module#AppModule', 'assets', compilerOptionsES, 'tsconfig-aot-es.json', 7, false],
['bootstrap-admin', 'admin/admin.module#AdminAppModule', 'assets-admin', compilerOptions, 'tsconfig-aot.json', 5, true],
['bootstrap-tools', 'tools/tools.module#ToolsAppModule', 'assets', compilerOptions, 'tsconfig-aot.json', 5, true],
];
function getScripts(args) {
const { analyze, main, admin } = args;
if (analyze || main) {
return [scripts[0]];
} else if (admin) {
return [scripts[2]];
} else {
return scripts;
}
}
module.exports = (args = {}) =>
getScripts(args)
.map(([script, entry, outDir, compilerOptions, tsConfigPath, ecma, TOOLS]) => merge(common, {
mode: 'production',
performance: {
maxEntrypointSize: 10000000,
maxAssetSize: 10000000,
},
entry: {
[script]: `./ts/${script}`,
},
output: Object.assign({}, common.output, {
filename: '[name]-[chunkhash:10].js',
path: path.resolve(__dirname, 'build', outDir, 'scripts'),
}),
devtool: script === 'bootstrap' ? 'source-map' : false,
node: { Buffer: false },
module: {
rules: [
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
use: [
{ loader: '@ngtools/webpack', options: { sourcemap: true, compilerOptions } },
],
},
],
},
optimization: {
minimizer: [
new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
ecma,
mangle: !args.debug,
output: { comments: false },
compress: ecma !== 5 ? { inline: 1 } : {},
},
}),
],
},
plugins: [
new AngularCompilerPlugin({ tsConfigPath, entryModule: `src/ts/components/${entry}` }),
(script === 'bootstrap' && !args.analyze) ? new WrapperPlugin({ test: /\.js$/, header: analytics }) : undefined,
args.analyze ? new BundleAnalyzerPlugin({ analyzerMode: 'static' }) : undefined,
new webpack.DefinePlugin({ DEVELOPMENT: false, TOOLS, SERVER: false, BETA: !!args.beta, TIMING: !!args.timing, TESTS: false }),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
].filter(x => x),
}));