-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
174 lines (170 loc) · 4.97 KB
/
webpack.config.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const path = require('path');
const autoprefixer = require('autoprefixer');
const postcssUrl = require('postcss-url');
const cssnano = require('cssnano');
const {UglifyJsPlugin} = require('webpack').optimize;
const {AotPlugin} = require('@ngtools/webpack');
const minimizeCss = true;
const baseHref = "";
const deployUrl = "";
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const {DefinePlugin} = require('webpack');
const commonConfig = require('./webpack.config.common');
const merge = require('webpack-merge');
const postcssPlugins = function () {
// safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
const importantCommentRe = /@preserve|@license|[@#]\s*source(?:Mapping)?URL|^!/i;
const minimizeOptions = {
preset: ['default', {
//autoprefixer: false,
safe: true,
//mergeLonghand: false,
discardComments: {remove: (comment) => !importantCommentRe.test(comment)},
//discardDuplicates: true
}]
};
return [
postcssUrl({
url: (URL) => {
// Only convert root relative URLs, which CSS-Loader won't process into require().
if (!URL.startsWith('/') || URL.startsWith('//')) {
return URL;
}
if (deployUrl.match(/:\/\//)) {
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
return `${deployUrl.replace(/\/$/, '')}${URL}`;
}
else if (baseHref.match(/:\/\//)) {
// If baseHref contains a scheme, include it as is.
return baseHref.replace(/\/$/, '') +
`/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
}
else {
// Join together base-href, deploy-url and the original URL.
// Also dedupe multiple slashes into single ones.
return `/${baseHref}/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
}
}
}),
autoprefixer(),
].concat(minimizeCss ? [cssnano(minimizeOptions)] : []);
};
const environmentFiles = {
'dev': 'environments/environment.ts',
'stag': 'environments/environment.stag.ts',
'prod': '/src/environments/environment.prod.ts'
};
const envFile= environmentFiles['prod'];
let exported = merge(commonConfig,
{
"entry": {
"main": [
"./src/main.ts",
"./src/assets/sass/main.scss"
],
"polyfills": [
"./src/polyfills.ts"
],
"vendor": [
"./src/assets/css/styles.css"
]
},
"output": {
"path": path.join(process.cwd(), "dist"),
"filename": "[name].[hash].bundle.js",
"chunkFilename": "[id].chunk.js"
},
"module": {
"rules": [
{
"test": /\.css$/,
"use": ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
"loader": "css-loader",
"options": {
"sourceMap": false,
"importLoaders": 1,
}
},
{
"loader": "postcss-loader",
"options": {
"ident": "postcss",
"plugins": postcssPlugins
}
}
]
})
},
{
"test": /\.scss$|\.sass$/,
"use": ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
"loader": "css-loader",
"options": {
"sourceMap": false,
"importLoaders": 2
}
},
{
"loader": "postcss-loader",
"options": {
"ident": "postcss",
"plugins": postcssPlugins
}
},
{
"loader": "sass-loader",
"options": {
"sourceMap": false,
"precision": 8,
"includePaths": []
}
}
]
})
},
]
},
"plugins": [
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('prod')
}
}),
new AotPlugin({
"mainPath": __dirname + "/src/main.aot.ts",
"replaceExport": false,
"hostReplacementPaths": {
"/src/environments/environment.ts": envFile
},
"exclude": [],
"tsConfigPath": __dirname + "/tsconfig-aot.json",
"skipCodeGeneration": true,
"entryModule": __dirname + "/src/app/app.module#AppModule",
}),
new ExtractTextPlugin({allChunks: true, filename: 'stylesheets/[name].[contenthash].css'}),
//new UglifyJsPlugin()
],
"node": {
"fs": "empty",
"global": true,
"crypto": "empty",
"tls": "empty",
"net": "empty",
"process": true,
"module": false,
"clearImmediate": false,
"setImmediate": false
},
"devServer": {
"historyApiFallback": true
}
});
module.exports = function (env, args) {
return exported;
};