forked from adventurerscodex/adventurerscodex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
100 lines (95 loc) · 3.06 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
90
91
92
93
94
95
96
97
98
99
100
const webpack = require('webpack');
const merge = require('webpack-merge');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const common = require('./webpack.common.js');
const package_ = require('./package.json');
let config = merge(common, {
mode: 'production',
output: {
filename: '[name].[chunkhash].js'
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
mangle: false,
}
})
],
splitChunks: {
chunks: 'all'
}
},
resolve: {
alias: {
// Use minified versions of dependencies that don't automatically do this
knockout$: 'knockout/build/output/knockout-latest.js', // Will do this in 3.5
toastr$: 'toastr/build/toastr.min.js',
'jquery-validation$': 'jquery-validation/dist/jquery.validate.min.js'
}
},
plugins: [
new CleanWebpackPlugin(['dist']),
// new CompressionWebpackPlugin(),
new webpack.DefinePlugin({
// Some package detect NODE_ENV to determine which build to use
'process.env': {
NODE_ENV: JSON.stringify('production')
},
/**
* Application's version number.
* Used to determine which migration scripts to run.
*/
'VERSION': JSON.stringify(package_.version),
/**
* Date and time the build was created
*/
'BUILD_DATE': JSON.stringify((new Date()).toLocaleString()),
/**
* Current year in yyyy format.
*/
'CURRENT_YEAR': JSON.stringify((new Date()).getFullYear()),
// Read from Environment
/**
* The string representation of the environment name.
*/
'ENVIRONMENT': process.env.ENVIRONMENT,
/**
* The App's Client ID for the API.
*/
'CLIENT_ID': process.env.CLIENT_ID,
/**
* The URL of the host application.
*/
'HOST_URL': process.env.HOST_URL,
/**
* The URL of the Web-Socket Server
*/
'WS_URL': process.env.WS_URL,
/**
* The URL of the homepage.
*/
'HOME_URL': process.env.HOME_URL,
/**
* The URL of the user's account profile.
*/
'ACCOUNT_URL': process.env.ACCOUNT_URL,
/**
* The URL to the login page.
*/
'LOGIN_URL': process.env.LOGIN_URL,
})
]
});
if (process.env.ENVIRONMENT == 'test') {
config = merge(config, {
devtool: 'cheap-module-eval-source-map'
});
}
module.exports = config;