This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
/
webpack.config.js
237 lines (227 loc) · 6.83 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-disable */
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HappyPack = require('happypack');
const path = require('path');
const config = require('./server/lib/configuration').getProperties();
const ENV = config.env;
const webpackConfig = {
mode: ENV,
context: path.resolve(__dirname, 'app/scripts'),
entry: {
app: './app.js',
appDependencies: [
'lib/jquery',
'backbone',
'canvasToBlob',
'cocktail-lib',
'duration',
'es6-promise',
'jquery',
'mailcheck',
'js-md5',
'modal',
'raven',
'speed-trap',
'ua-parser-js',
'uuid',
'vat',
'webrtc',
'styles/main.scss'
],
head: './head/boot.js'
},
output: {
crossOriginLoading: 'anonymous',
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist', config.jsResourcePath),
publicPath: `/${config.jsResourcePath}/`
},
resolve: {
extensions: ['.js'],
modules: [
path.resolve(__dirname, 'app/scripts'),
path.resolve(__dirname, 'app/scripts/templates'),
path.resolve(__dirname, 'app'),
path.resolve(__dirname, 'node_modules'),
'node_modules'
],
alias: {
canvasToBlob: path.resolve(__dirname, 'node_modules/blueimp-canvas-to-blob/js/canvas-to-blob'),
'cocktail-lib': path.resolve(__dirname, 'node_modules/backbone.cocktail/Cocktail'),
cocktail: path.resolve(__dirname, 'app/scripts/lib/cocktail'),
draggable: path.resolve(__dirname, 'node_modules/jquery-ui/ui/widgets/draggable'),
duration: path.resolve(__dirname, 'node_modules/duration-js/duration'),
'es6-promise': path.resolve(__dirname, 'node_modules/es6-promise/dist/es6-promise'),
fxaClient: 'fxa-js-client/client/FxAccountClient',
fxaCryptoDeriver: path.resolve(__dirname, 'node_modules/fxa-crypto-relier/dist/fxa-crypto-relier/fxa-crypto-deriver'),
fxaPairingChannel: path.resolve(__dirname, 'node_modules/fxa-pairing-channel/dist/FxAccountsPairingChannel.babel.umd.js'),
'base32-decode': path.resolve(__dirname, 'node_modules/base32-decode/index'),
// jwcrypto is used by the main app and only contains DSA
// jwcrypto.rs is used by the unit tests to unbundle and verify
// assertions, which require RSA.
jwcrypto: path.resolve(__dirname, 'app/scripts/vendor/jwcrypto/jwcrypto.ds'),
'jwcrypto.rs': path.resolve(__dirname, 'app/scripts/vendor/jwcrypto/jwcrypto.rs'),
mailcheck: path.resolve(__dirname, 'node_modules/mailcheck/src/mailcheck'),
'js-md5': path.resolve(__dirname, 'node_modules/js-md5/src/md5'),
mocha: 'mocha/mocha',
modal: path.resolve(__dirname, 'node_modules/jquery-modal/jquery.modal'),
raven: path.resolve(__dirname, 'node_modules/raven-js/dist/raven'),
sinon: path.resolve(__dirname, 'node_modules/sinon/pkg/sinon'),
'touch-punch': path.resolve(__dirname, 'node_modules/jquery-ui-touch-punch-amd/jquery.ui.touch-punch'),
'ua-parser-js': path.resolve(__dirname, 'node_modules/ua-parser-js/src/ua-parser'),
uuid: path.resolve(__dirname, 'node_modules/node-uuid/uuid'),
vat: path.resolve(__dirname, 'node_modules/node-vat/vat'),
webrtc: path.resolve(__dirname, 'node_modules/webrtc-adapter-test/adapter')
}
},
module: {
rules: [
{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
},
{
loader: 'expose-loader',
options: '$'
}],
},
{
test: require.resolve('mocha'),
use: [{
loader: 'expose-loader',
options: 'mocha'
}],
},
{
test: /\.mustache$/,
loader: 'fxa-mustache-loader'
},
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'app', 'scripts')
],
exclude: [
path.resolve(__dirname, 'app', 'scripts', 'vendor'),
path.resolve(__dirname, 'app', 'scripts', 'templates')
],
use: {
loader: 'happypack/loader',
}
},
{
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].css',
outputPath: '../../app/styles',
}
},
{
loader: 'extract-loader'
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader'
},
]
}
]
},
optimization: {
splitChunks: { // CommonsChunkPlugin()
cacheGroups: {
appDependencies: {
test: /[\\/]node_modules[\\/]/,
name: 'appDependencies',
chunks: 'initial'
}
}
},
},
plugins: ([
new HappyPack({
loaders: [{
path: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['babel-preset-es2015'],
plugins: ['babel-plugin-syntax-dynamic-import', 'transform-class-properties']
}
}],
threads: 4,
debug: false
}),
// dynamically loaded routes cause the .md file to be read and a
// warning to be displayed on the console. Just ignore them.
new webpack.IgnorePlugin(/\.md$/)
]),
stats: { colors: true },
node: {
crypto: 'empty'
},
// See https://webpack.js.org/configuration/devtool/ to
// configure source maps to personal preferences.
devtool: 'source-map'
};
if (ENV === 'development') {
Object.assign(webpackConfig.entry, {
test: '../tests/webpack.js',
testDependencies: [
'jquery',
'chai',
'jquery-simulate',
'mocha',
'sinon',
]
});
} else {
Object.assign(webpackConfig.optimization, {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
compress: {
unsafe_comps: true,
properties: true,
keep_fargs: false,
pure_getters: true,
collapse_vars: true,
unsafe: true,
warnings: false,
sequences: true,
dead_code: true,
drop_debugger: true,
comparisons: true,
conditionals: true,
evaluate: true,
booleans: true,
loops: true,
unused: true,
hoist_funs: true,
if_return: true,
join_vars: true,
drop_console: true
},
},
sourceMap: true,
cache: true,
parallel: true
}),
]
});
}
module.exports = webpackConfig;