-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
220 lines (213 loc) · 8.66 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const { AureliaPlugin } = require('aurelia-webpack-plugin');
const { ProvidePlugin, DefinePlugin, IgnorePlugin, ContextReplacementPlugin, SourceMapDevToolPlugin }
= require('webpack');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// config helpers:
const ensureArray = (config) => config && (Array.isArray(config) ? config : [config]) || []
const when = (condition, config, negativeConfig) =>
condition ? ensureArray(config) : ensureArray(negativeConfig)
// primary config:
const title = 'dxDAO';
let outDir;
const srcDir = path.resolve(__dirname, 'src');
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
const baseUrl = '/';
/**
* @return {webpack.Configuration}
*/
module.exports = ({ production, server, coverage } = {}) => {
let env = production ? 'production' : 'development';
outDir = path.resolve(__dirname, production ? 'dist_prod' : 'dist');
console.log(`env: ${env}`);
return {
mode: env,
resolve: {
extensions: ['.ts', '.js'],
modules: [srcDir, 'node_modules'],
alias: {
// prepend '~' to import path in order to use this alias
// "bootstrap-sass": path.resolve(nodeModulesDir,"bootstrap/scss/"),
// "mdbootstrap-sass": path.resolve(nodeModulesDir,"mdbootstrap/sass/mdb/free/"),
"bootstrap": path.resolve(nodeModulesDir, "bootstrap/"),
"BMD": path.resolve(nodeModulesDir, "bootstrap-material-design/scss/"),
"static": path.resolve(__dirname, "static"),
}
},
devtool: production ? 'source-map' : 'eval-source-map',
entry: {
app: ['aurelia-bootstrapper'],
vendor: [
'bluebird',
'@daostack/arc.js'
],
},
output: {
path: outDir,
publicPath: baseUrl,
filename: production ? '[name].[chunkhash].bundle.js' : '[name].[hash].bundle.js',
sourceMapFilename: production ? '[name].[chunkhash].bundle.map' : '[name].[hash].bundle.map',
chunkFilename: production ? '[name].[chunkhash].chunk.js' : '[name].[hash].chunk.js'
},
devServer: {
contentBase: outDir,
// serve index.html for all 404 (required for push-state)
historyApiFallback: true,
},
optimization: {
runtimeChunk: "single", // enable "runtime" chunk
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all"
}
}
},
minimizer: [
new TerserPlugin({
test: /\.js($|\?)/i,
sourceMap: false,
extractComments: true,
parallel: true,
terserOptions: {
ecma: 6,
mangle: {
reserved: ['BigNumber'],
}
}
})
]
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
// CSS required in templates cannot be extracted safely
// because Aurelia would try to require it again in runtime
issuer: [{ not: [{ test: /\.html$/i }] }],
use: [
production ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
{
loader: 'postcss-loader',
// avoid error: "No PostCSS Config found in"
options: {
plugins: (loader) => [
require('postcss-smart-import'),
require('autoprefixer'),
]
}
},
'sass-loader',
]
},
{ test: /\.html$/i, loader: 'html-loader' },
{ test: /\.ts$/i, loader: 'awesome-typescript-loader', exclude: nodeModulesDir },
// { test: /\.json$/i, loader: 'json-loader' },
// use Bluebird as the global Promise implementation:
{ test: /[\/\\]node_modules[\/\\]bluebird[\/\\].+\.js$/, loader: 'expose-loader?Promise' },
// exposes jQuery globally as $ and as jQuery:
{ test: require.resolve('jquery'), loader: 'expose-loader?$!expose-loader?jQuery' },
// 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 } },
{ 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' },
...when(coverage, {
test: /\.[jt]s$/i, loader: 'istanbul-instrumenter-loader',
include: srcDir, exclude: [/\.{spec,test}\.[jt]s$/i],
enforce: 'post', options: { esModules: true },
})
]
},
plugins: [
new DefinePlugin({
'process.env': {
env: JSON.stringify(env)
},
}),
new AureliaPlugin(),
new ProvidePlugin({
Promise: 'bluebird',
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
Waves: 'node-waves'
}),
new HtmlWebpackPlugin({
template: 'index.ejs',
minify: production ? {
removeComments: true,
collapseWhitespace: true
} : undefined,
metadata: {
// available in index.ejs //
title, server, baseUrl
},
}),
new CopyWebpackPlugin([
{ from: 'static/favicon.ico' },
{ from: 'static/app-config.json' },
{ from: 'static/daostack-icon-white.svg' },
{ from: 'static/daostack-icon-black.svg' },
{ from: 'static/dutchx-white.svg' },
{ from: 'static/dutchx-blue.svg' },
{ from: 'static/generic_icon_white.svg' },
{ from: 'static/generic_icon_color.svg' },
{ from: 'static/eth_icon_white.svg' },
{ from: 'static/eth_icon_color.svg' },
{ from: 'static/mgn_icon_white.svg' },
{ from: 'static/mgn_icon_color.svg' },
{ from: 'static/gen_icon_white.svg' },
{ from: 'static/gen_icon_color.svg' },
{ from: 'src/schedule/DS_DXDAO_ARROW_ICON_white.svg' },
{ from: 'src/schedule/DS_DXDAO_ARROW_ICON_black.svg' },
{ from: 'static/t_blue.svg' },
{ from: 'static/t_white.svg' },
{ from: 'static/base.css' },
{ from: 'node_modules/font-awesome/fonts', to: 'fonts' },
{ from: 'node_modules/material-icons/iconfont/material-icons.css', to: 'fonts'},
{ from: 'node_modules/material-icons/iconfont/MaterialIcons-Regular.eot', to: 'fonts'},
{ from: 'node_modules/material-icons/iconfont/MaterialIcons-Regular.woff2', to: 'fonts'},
{ from: 'node_modules/material-icons/iconfont/MaterialIcons-Regular.woff', to: 'fonts'},
{ from: 'node_modules/material-icons/iconfont/MaterialIcons-Regular.ttf', to: 'fonts'},
{ from: 'static/fonts/dinpro', to: 'fonts' },
{ from: 'node_modules/font-awesome/css/font-awesome.min.css', to: 'font-awesome.min.css' },
{ from: 'node_modules/snackbarjs/dist/snackbar.min.css' },
{ from: 'node_modules/bootstrap-material-design/dist/css/bootstrap-material-design.min.css' },
]),
// remove all moment.js locale files
new IgnorePlugin(/^\.\/locale$/, /moment$/),
// filter ABI contract files
new ContextReplacementPlugin(
/@daostack[/\\]arc.js[/\\]migrated_contracts$/,
/Controller.json|Avatar.json|DAOToken.json|Reputation.json|ERC20.json|Auction4Reputation.json|ExternalLocking4Reputation.json|Locking4Reputation.json|LockingEth4Reputation.json|LockingToken4Reputation.json|PriceOracleInterface.json/),
new MiniCssExtractPlugin({
filename: production ? '[name].[hash].css' : '[name].css',
chunkFilename: production ? '[id].[hash].css' : '[id].css',
}),
...when(!production, [
new SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(outDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
}),
]),
...when(production, [
new CompressionPlugin({
test: /\.css$|\.js($|\?)/i
})
])
// , new BundleAnalyzerPlugin({ analyzerMode: 'static' })
],
}
}