-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
91 lines (86 loc) · 2.04 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
const path = require('path')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const ENV_PROD = 'production'
const ENV_DEV = 'development'
const ENV_TESTING = 'testing'
const NODE_ENV = process.env.NODE_ENV ? process.env.NODE_ENV.replace(' ', '') : ENV_PROD
const env = {
prod: NODE_ENV === ENV_PROD,
dev: NODE_ENV === ENV_DEV || NODE_ENV === ENV_TESTING,
test: NODE_ENV === ENV_TESTING,
}
const nodeModulesRegexp = /node_modules/
const getJavaScriptLoaders = () => {
if (!env.test) {
return [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: nodeModulesRegexp,
},
]
}
return [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: nodeModulesRegexp,
},
{
test: /\.js$/,
use: {
loader: 'istanbul-instrumenter-loader',
options: { esModules: true },
},
enforce: 'post',
exclude: /node_modules|\.test\.js/,
},
]
}
module.exports = {
devtool: !env.prod ? 'inline-source-map' : false,
entry: './src/',
output: {
path: path.join(__dirname, 'lib'),
filename: 'index.js',
libraryTarget: 'umd',
library: 'redux-restify',
globalObject: 'this',
},
mode: env.prod ? 'production' : 'development',
node: env.test ? {
fs: 'empty',
} : {},
module: {
rules: getJavaScriptLoaders().concat([]),
},
resolve: {
alias: {
'~': path.join(__dirname, 'src'),
},
modules: [
'node_modules',
],
extensions: ['.js', '.json'],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
PROD: JSON.stringify(env.prod),
DEV: JSON.stringify(env.dev),
TEST: JSON.stringify(env.test),
NODE_ENV: `"${NODE_ENV}"`,
},
}),
new webpack.ProvidePlugin({
key: 'keymaster',
}),
// new BundleAnalyzerPlugin(),
].concat(!env.prod ? [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
] : [
new webpack.ExtendedAPIPlugin(),
]),
}