-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
109 lines (100 loc) · 2.83 KB
/
webpack.config.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const nodeExternals = require('webpack-node-externals');
const {resolve} = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
target: "node",
entry: {
index: resolve(__dirname, 'src', 'index.ts'),
},
// Currently we need to add '.ts' to the resolve.extensions array.
resolve: {
modules: ['node_modules'],
extensions: [".ts", ".tsx", ".js"],
descriptionFiles: ['package.json'],
},
output: {
path: resolve(__dirname, 'dist'),
filename: '[name].js',
chunkFilename: '[name]-[id].js',
libraryTarget: 'commonjs2'
},
// Source maps support ('inline-source-map' also works)
devtool: false,
externals: [nodeExternals()],
stats: {
colors: true,
modules: true,
reasons: true,
errorDetails: true
},
node: {
console: false,
global: true,
process: true,
Buffer: true,
__filename: true,
__dirname: true,
setImmediate: true
},
// Add the loader for .ts files.
module: {
rules: [
{
enforce: 'pre',
test: /\.ts(x?)$/,
use: "source-map-loader",
exclude: /node_modules/,
},
{
test: /\.ts(x?)$/,
use: [
{loader: 'awesome-typescript-loader'}
],
include: [
resolve(__dirname, 'src')
]
}
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
}
}),
new webpack.optimize.OccurrenceOrderPlugin(),
// new JavaScriptObfuscator(),
new UglifyJSPlugin({
parallel: true,
sourceMap: false,
uglifyOptions: {
ecma: 8,
ie8: false,
warnings: false,
output: {
beautify: false,
keep_quoted_props: true,
shebang: false,
comments: false,
},
compress: {
properties: true,
dead_code: true,
drop_debugger: true,
unsafe_math: true,
conditionals: true,
loops: true,
if_return: true,
inline: true,
collapse_vars: true,
reduce_vars: true,
drop_console: true,
passes: 5,
keep_infinity: true,
}
}
}),
],
};