-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.ts
96 lines (83 loc) · 2.63 KB
/
webpack.config.ts
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
import {PluginOption} from './webpack/plugin.option';
import * as webpack from "webpack";
import * as path from "path";
import {RuleOption} from "./webpack/rule.option";
import {BaseOption} from "./webpack/base-option";
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const config = (): webpack.Configuration => {
// Read arguments that have been passed to webpack console.
const argv: { [key: string]: any } = require('yargs').argv;
// True if built is set to production mode.
// False if built is set to development mode.
const bProductionMode = 'production' === argv.mode.toLowerCase();
const bSourceMap = (argv['source-map'] === true || bProductionMode === false);
const baseOptions = new BaseOption(__dirname);
// Build path options.
let paths = {
root: __dirname,
source: baseOptions.loadSourceCodeFullPath(),
app: baseOptions.loadAppFullPath(),
dist: baseOptions.loadDistributedFolderPath()
};
//#region Code minimizer
let minimizer = [
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
mangle: false,
output: {
beautify: false,
},
extractComments: true
},
sourceMap: bSourceMap
})
];
if (!bProductionMode)
minimizer = [];
//#endregion
/*
* Module export.
* */
return {
context: paths.root,
devtool: bSourceMap ? 'source-map' : false,
entry: {
'app': [path.resolve(paths.app, 'app.ts')]
},
optimization: {
runtimeChunk: 'single',
minimize: bProductionMode,
minimizer: minimizer,
splitChunks: {
chunks: 'all',
cacheGroups: {
default: {
enforce: true,
priority: 1
},
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: 2,
name: 'vendors',
enforce: true,
chunks: 'async'
}
}
}
},
module: {
rules: new RuleOption().loadRules()
},
plugins: new PluginOption().loadOptions(argv, bProductionMode, paths),
output: {
path: path.resolve(paths.dist),
filename: '[name].[hash].js'
},
resolve: {
extensions: [".ts", ".tsx", ".js"]
},
};
};
export default config;