-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (67 loc) · 1.73 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
const { readFileSync } = require('fs');
const { resolve } = require('path');
const rxPaths = require('rxjs/_esm5/path-mapping');
const {
BannerPlugin,
EnvironmentPlugin,
optimize: { UglifyJsPlugin, ModuleConcatenationPlugin },
} = require('webpack');
const merge = require('webpack-merge');
const { argv: { env } } = require('yargs');
const { name: filename, version } = require('./package.json');
const banner = readFileSync(resolve('./_includes/header.txt'), 'utf-8');
const flatten = [(a, x) => a.concat(x), []];
function envConfig() {
switch (env) {
case 'prod':
return {
plugins: [
new BannerPlugin({ banner, raw: true }),
new EnvironmentPlugin({ DEBUG: false }),
new UglifyJsPlugin(),
],
};
default:
return {
devtool: 'source-map',
plugins: [new EnvironmentPlugin({ DEBUG: true })],
};
}
}
module.exports = merge(
{
entry: resolve('./_js/src/index.js'),
output: {
path: resolve('./assets/js'),
filename: `${filename}-${version}.js`,
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
options: {
presets: [['env', { modules: false }]],
babelrc: false,
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
],
},
resolve: {
modules: [
resolve('./_js'),
resolve('./node_modules'),
process.env.NODE_PATH ? resolve(process.env.NODE_PATH) : [],
].reduce(...flatten),
extensions: ['.json', '.js'],
symlinks: true,
alias: rxPaths(),
},
plugins: [new ModuleConcatenationPlugin()],
},
envConfig(),
);