forked from beetledev/web-wallet
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
280 lines (227 loc) · 9.88 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const { ProvidePlugin } = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { AureliaPlugin, ModuleDependenciesPlugin } = require('aurelia-webpack-plugin');
let options = {
env: 'dev',
prod: false,
coverage: false,
analyze: false,
devHost: 'localhost',
devPort: 9000
}
module.exports = env => {
if ((env && env.production) || ((process.env.NODE_ENV) && (process.env.NODE_ENV.toLowerCase().startsWith('prod')))) {
options.env = 'prod';
options.prod = true;
}
const ensureArray = (config) => config && (Array.isArray(config) ? config : [config]) || [];
const when = (condition, config, negativeConfig) => condition ? ensureArray(config) : ensureArray(negativeConfig);
const outDir = path.resolve(__dirname, 'dist');
const srcDir = path.resolve(__dirname, 'src');
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
const baseUrl = '/';
return {
resolve: {
extensions: ['.js'],
modules: [srcDir, 'node_modules', 'vendor'],
alias: {
'@fortawesome/fontawesome-free-solid$': '@fortawesome/fontawesome-free-solid/shakable.es.js'
}
},
entry: {
app: ['aurelia-bootstrapper']
},
mode: options.prod ? 'production' : 'development',
// we explicitly optimize by including the uglify plugin, otherwise it runs twice
// if didn't include it explicitly, this would run it automatically (if = true)
optimization: {
minimize: options.prod ? false : false
},
output: {
path: outDir,
publicPath: baseUrl,
filename: options.prod ? '[name].[chunkhash].bundle.js' : '[name].[hash].bundle.js',
sourceMapFilename: options.prod ? '[name].[chunkhash].bundle.map' : '[name].[hash].bundle.map',
chunkFilename: options.prod ? '[name].[chunkhash].chunk.js' : '[name].[hash].chunk.js'
},
devServer: {
contentBase: outDir,
port: options.devPort,
host: options.devHost,
disableHostCheck: true,
historyApiFallback: true,
watchOptions: {
aggregateTimeout: 500,
poll: 3000
}
},
devtool: options.prod ? 'nosources-source-map' : 'cheap-module-eval-source-map',
module: {
rules: [
// HTML loader
{ test: /\.html$/, use: ['html-loader'], exclude: path.join(__dirname, 'index.html') },
// HTML loader with minification options - can also implement general minication at different processing stage)
//{ test: /\.html$/, use: [ 'raw-loader', 'html-minifier-loader' ], exclude: path.join(__dirname, 'index.html') },
// JSON loader
{ test: /\.json$/, loader: "json-loader", exclude: [path.resolve(__dirname, 'node_modules'), path.resolve(__dirname, 'vendor')] },
// CSS loader OLD
// { test: /\.css?$/, use: [ 'style-loader', 'css-loader' ] },
// CSS required in JS/TS files should use the style-loader that auto-injects it into the website
// only when the issuer is a .js/.ts file, so the loaders are not applied inside html templates
{
test: /\.css$/i,
issuer: [{ not: [{ test: /\.html$/i }] }],
use: options.prod ? ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
}) : ['style-loader', 'css-loader'],
},
{
test: /\.css$/i,
issuer: [{ test: /\.html$/i }],
// CSS required in templates cannot be extracted safely
// because Aurelia would try to require it again in runtime
use: 'css-loader'
},
// SCSSS
{
test: /\.scss$/,
use: [{
loader: "style-loader" // inject CSS to page
}, {
loader: "css-loader", // translates CSS into CommonJS modules
options: {
sourceMap: true
}
}, {
loader: 'postcss-loader', // Run post css actions
options: {
sourceMap: true,
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
require('precss'),
require('autoprefixer')
];
}
}
}, {
loader: "resolve-url-loader",
options: {
sourceMap: true
}
}, {
loader: "sass-loader",
options: {
sourceMap: true
}
}]
},
// JS
{
test: /\.js$/i,
loader: 'babel-loader',
exclude: [nodeModulesDir, '/vendor/'],
options: options.coverage ? {
sourceMap: 'inline',
plugins: ['istanbul']
} : { 'plugins': ['lodash'] },
},
//
// Fonts, Images & SVG
//
// embed small images and fonts as Data Urls and larger ones as files:
{ test: /\.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } },
// This is the only one that seems to works with font-awesome
{ test: /\.(woff|woff2)(\?\S*)?$/, loader: 'url-loader?limit=100000&name=[name].[ext]' },
// Default aurelia-cli version
// { test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff2' } },
// { test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff' } },
// load these fonts normally, as files
{ test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'file-loader' },
// Bootstrap 4
{ test: /bootstrap\/dist\/js\/umd\//, use: 'imports-loader?jQuery=jquery' },
// Bootstrap 3
//{ test: /bootstrap-sass\/assets\/javascripts\//, use: 'imports-loader?jQuery=jquery' },
]
},
plugins: [
new AureliaPlugin(),
new ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Map: 'core-js/es6/map',
WeakMap: 'core-js/es6/weak-map',
Promise: 'core-js/es6/promise',
regeneratorRuntime: 'regenerator-runtime', // await/async
}),
new ModuleDependenciesPlugin({
'aurelia-testing': ['./compile-spy', './view-spy']
}),
new HtmlWebpackPlugin({
template: 'index.ejs',
minify: options.prod ? {
removeComments: true,
collapseWhitespace: false
} : undefined,
metadata: { // available in index.ejs
env: options.env,
baseUrl
}
}),
new LodashModuleReplacementPlugin({
'cloning': true,
'collections': true
}),
new CopyWebpackPlugin([
//{ from: 'favicon.ico', to: 'favicon.ico' },
{ from: 'config', to: 'config' },
{ from: 'static', to: 'static' }
]),
//new webpack.DefinePlugin({
// PRODUCTION: JSON.stringify(true),
// NODE_ENV: JSON.stringify('production')
// //'process.env': {
// // 'NODE_ENV': JSON.stringify('production'),
// //}
//}),
...when(options.prod, new ExtractTextPlugin({
filename: options.prod ? '[chunkhash].css' : '[id].css',
allChunks: true
})),
...when(options.analyze, new BundleAnalyzerPlugin())
].concat(options.prod ? [
// Prevents the inclusion of duplicate code into your bundle
// new webpack.optimize.DedupePlugin(),
new UglifyJsPlugin({
uglifyOptions: {
ecma: 6,
ie8: false,
keep_fnames: true,
keep_classnames: true,
sourceMap: false,
mangle: {
reserved: ['BigInteger', 'ECPair', 'Point']
}
}
})
] : [
]),
performance: {
hints: false
},
//node: {
// console: true,
// fs: 'empty',
// net: 'empty',
// tls: 'empty',
// child_process: 'empty'
//},
};
}