-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.prod.js
166 lines (148 loc) · 4.16 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
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
// Production Webpack Configuration
// Plugins
const webpack = require('webpack'); // webpack built-in plugins
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const sGrid = require('s-grid');
const AutoprefixerStylus = require('autoprefixer-stylus');
const CompressionPlugin = require("compression-webpack-plugin");
const { BaseHrefWebpackPlugin } = require('base-href-webpack-plugin');
// Helper for resolving paths
const helpers = require('./helpers.js');
// Environment variables for use in the Angular2 App
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
// Base Href
// NOTE(rex): Taken from config: { sub: 'folderName/' } in package.json.
const BH = process.env.npm_package_config_sub + '/';
module.exports = {
entry: {
'app': './src/prod.ts'
},
output: {
filename: 'build.[hash].js',
chunkFilename: '[id].[hash].chunk.js',
path: helpers.root('.dist'),
publicPath: BH,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: 'config/tsconfig.prod.json'
}
},
{
loader: 'angular2-template-loader',
}
],
include: [helpers.root('src'), helpers.root('node_modules', '@encurate')],
exclude: [/\.(spec|e2e)\.ts$/, /node_modules\/(?!(@encurate)\/).*/]
},
{
test: /\.html$/,
use: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
use: 'file-loader?name=img/[name].[hash].[ext]'
},
{
test: /\.styl$/,
use: [
'raw-loader',
'stylus-loader',
],
include: [helpers.root('src', 'app')],
exclude: [helpers.root('node_modules'), helpers.root('src', 'styles')]
},
{
test: /\.styl$/,
use: [
'style-loader',
'css-loader',
'stylus-loader',
],
include: [helpers.root('src', 'styles')],
exclude: [helpers.root('node_modules'), helpers.root('src', 'app')]
},
]
},
plugins: [
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./app'), // location of your app
{} // a map of your routes
),
// Enable production flag
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
}),
new webpack.NoEmitOnErrorsPlugin(),
/* NOTE(rex): Some of these options will mess with angular, mangle is a bit one.
* I'm not going to dick around with this any more, but if you are back here,
* prob check out additional options!
*/
new UglifyJsPlugin({
sourceMap: false,
uglifyOptions: {
// ecma: 8,
warnings: false,
mangle: false,
// output: {
// comments: false,
// beautify: false,
// },
// toplevel: false,
// ie8: false,
// safari10: false,
},
}),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
}),
new webpack.LoaderOptionsPlugin({
htmlLoader: {
minimize: false // workaround for ng2
}
}),
// Set base href in index
new BaseHrefWebpackPlugin({ baseHref: BH }),
new HtmlWebpackPlugin({
template: './src/index.html',
favicon: './src/favicon.ico',
}),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery'
}),
new webpack.LoaderOptionsPlugin({
test: /\.styl$/,
stylus: {
default: {
use: [
sGrid(),
AutoprefixerStylus(),
],
},
},
}),
],
};