This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.prod.js
115 lines (79 loc) · 2.6 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
110
111
112
113
114
115
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var ngToolsWebpack = require('@ngtools/webpack');
var { common, buildDefines } = require('./webpack.common.js');
// ensure production environment
process.env.NODE_ENV = 'production';
var config = {
// Source maps are completely regenerated for each chunk at each build
devtool: 'source-map',
// No need to set `context`, base directory for resolving entry points:
// entry point paths are relative to current directory
// Client application only, no dev server
entry: {
'vendor': common.relPaths.vendorEntryAot,
'main': common.relPaths.mainEntryAot,
},
output: {
path: common.absPaths.buildOutput,
filename: common.relPaths.bundleJs,
chunkFilename: common.relPaths.chunk,
publicPath: common.urls.public,
},
module: {
rules: [
// Pre-loaders
// none
// Loaders
common.rules.typescript.aot,
common.rules.sass.global,
common.rules.sass.component,
common.rules.css.global,
common.rules.css.component,
common.rules.html,
// Post-loaders
// none
],
// speed up build by excluding some big libraries from parsing
noParse: common.noParse,
},
resolve: {
extensions: common.resolve.extensions,
},
plugins: [
new webpack.DefinePlugin(buildDefines()),
// TODO exclude this plugin until this is fixed:
// https://github.com/angular/angular-cli/issues/4431
// https://github.com/angular/angular-cli/issues/6518
/*
// Provides context to Angular's use of System.import
new webpack.ContextReplacementPlugin(
common.patterns.angularContext,
common.absPaths.clientSrc,
{}
),
*/
new webpack.optimize.CommonsChunkPlugin({
name: ['main', 'vendor'],
filename: common.relPaths.bundleJs,
minChunks: mod => common.patterns.nodeModules.test(mod.resource),
}),
new ExtractTextPlugin(common.relPaths.bundleCss),
// use @ngtools for AoT build
new ngToolsWebpack.AotPlugin({
tsConfigPath: './tsconfig-aot.json',
skipMetadataEmit: true,
entryModule: 'src/app/module#AppModule', // drop extension and trailing `./`
}),
// Minimize scripts
new webpack.optimize.UglifyJsPlugin(),
// Only emit files when there are no errors
new webpack.NoEmitOnErrorsPlugin(),
// Copy static assets from their folder to common output folder
new CopyWebpackPlugin([{
from: common.absPaths.staticFiles,
}]),
],
};
module.exports = config;