-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
127 lines (122 loc) · 2.98 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
const path = require('path');
const webpack = require('webpack');
const env = process.env.WEBPACK_ENV;
const libraryName = 'electre';
const plugins = [];
let extension = '.js';
let devtool = 'inline-source-map';
if (env === 'build' || env === 'cov') {
extension = '.min.js';
if (env === 'build') {
devtool = 'cheap-module-source-map';
} else {
plugins.push('istanbul');
devtool = false;
}
}
const nodeConfig = {
devtool,
entry: path.resolve(__dirname, 'src/electre.node.js'),
// Compile for usage in a Node.js-like environment (uses Node.js require to load chunks)
target: 'node',
// for tiny-worker to access its file worker.js
node: {
__dirname: false,
__filename: false,
},
output: {
path: path.resolve(__dirname, 'lib'),
filename: `electre.node${extension}`,
library: libraryName,
// Export by setting module.exports: module.exports = xxx
libraryTarget: 'commonjs2',
},
// tiny-worker imported from the environment during runtime
// since Joi is used only in workers, we don't have to declare it as external
externals: [
'tiny-worker',
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
plugins,
},
},
},
],
},
plugins: [
new webpack.DefinePlugin({
EXTENSION: JSON.stringify(extension),
}),
],
};
const webConfig = {
devtool,
entry: path.resolve(__dirname, 'src/electre.web.js'),
// Compile for usage in a browser-like environment
target: 'web',
// as of https://github.com/jeffbski/joi-browser/blob/master/webpack.config.js
// in order to use joi in browser
node: {
global: true,
Buffer: 'mock',
crypto: 'empty',
net: 'empty',
dns: 'empty',
},
output: {
path: path.resolve(__dirname, 'lib'),
filename: `electre.web${extension}`,
library: libraryName,
// Export to AMD, CommonJS2 or as property in root
libraryTarget: 'umd',
umdNamedDefine: true,
},
module: {
rules: [
// worker loader module for webpack
{
test: /\worker.js$/,
use: {
loader: 'worker-loader',
options: {
inline: false,
name: `workers/[name]${extension}`,
},
},
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
plugins,
},
},
},
{
// In order to use Joi when need to babelify joi, isemail, hoek, and topo's lib
test: /[\\/]node_modules[\\/](joi[\\/]lib[\\/]|isemail[\\/]lib[\\/]|hoek[\\/]lib[\\/]|topo[\\/]lib[\\/])/,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
},
},
},
],
},
};
module.exports = [
nodeConfig,
webConfig,
];