-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebpack.config.js
More file actions
105 lines (82 loc) · 2.32 KB
/
webpack.config.js
File metadata and controls
105 lines (82 loc) · 2.32 KB
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
/* eslint-disable strict, no-console, object-shorthand */
/* eslint-disable import/no-extraneous-dependencies, import/newline-after-import */
'use strict'
const path = require('path')
const webpack = require('webpack')
const combineLoaders = require('webpack-combine-loaders')
const PRODUCTION = process.env.NODE_ENV === 'production'
const PATHS = {
ILP_PLUGIN: path.resolve(__dirname, 'src/lib/bigchaindb_ledger_plugin.js'),
BUILD: path.resolve(__dirname, 'build'),
BUNDLE: path.resolve(__dirname, 'bundle'),
NODE_MODULES: path.resolve(__dirname, 'node_modules'),
}
/** EXTERNAL DEFINITIONS INJECTED INTO APP **/
const DEFINITIONS = {
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
BDB_SERVER_URL: JSON.stringify(`${process.env.BDB_SERVER_URL || 'http://localhost:9984'}`),
BDB_WS_URL: JSON.stringify(`${process.env.BDB_WS_URL || 'ws://localhost:9985'}`),
},
}
/** PLUGINS **/
const PLUGINS = [
new webpack.DefinePlugin(DEFINITIONS),
new webpack.NoEmitOnErrorsPlugin(),
]
const PROD_PLUGINS = [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: true,
}),
new webpack.LoaderOptionsPlugin({
debug: false,
minimize: true
}),
]
if (PRODUCTION) {
PLUGINS.push(...PROD_PLUGINS)
}
/** LOADERS **/
const JS_LOADER = combineLoaders([
{
loader: 'babel-loader',
options: {
presets: ['es2015'],
},
query: {
cacheDirectory: true,
},
},
])
const LOADERS = [
{
test: /\.jsx?$/,
exclude: [PATHS.NODE_MODULES],
loader: JS_LOADER,
},
]
/** EXPORTED WEBPACK CONFIG **/
module.exports = {
entry: PATHS.ILP_PLUGIN,
output: {
filename: PRODUCTION ? 'bundle.min.js' : 'bundle.js',
library: 'ilp-plugin-bigchaindb',
libraryTarget: 'umd',
path: PRODUCTION ? PATHS.BUNDLE : PATHS.BUILD,
},
devtool: PRODUCTION ? '#source-map' : '#inline-source-map',
resolve: {
extensions: ['.js', '.jsx'],
modules: ['node_modules'], // Don't use absolute path here to allow recursive matching
},
plugins: PLUGINS,
module: {
rules: LOADERS,
},
}