forked from mosaicdao/mosaic.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
102 lines (96 loc) · 2.22 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
'use strict';
const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const rootPreFix = '.';
const entryFile = rootPreFix + '/index.js';
const polyfillFile = '@babel/polyfill';
const commonConfig = (target, babelTargets) => {
return {
target,
entry: {
mosaic: [polyfillFile, entryFile],
},
output: {
path: path.resolve(__dirname, 'lib'),
filename: `[name].${target}.js`,
},
externals: {
web3: 'web3',
'web3-eth-accounts': 'web3-eth-accounts',
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/\.\/AbiBinProvider-node\.js/,
`./AbiBinProvider-${target}.js`,
),
],
module: {
rules: [
{
test: /\.js$/,
exclude: path.resolve(__dirname, 'node_modules'),
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: babelTargets,
},
],
],
},
},
],
},
{
test: /package\.json$/,
loader: 'package-json-cleanup-loader',
options: {
only: ['version', 'name', 'otherParam'],
},
},
],
},
optimization: {
minimize: target == 'web' ? true : false,
minimizer: [new UglifyJsPlugin()],
},
};
};
const webConfig = () => {
const config = commonConfig('web', '> 0.25%, not dead');
return {
...config,
output: {
...config.output,
library: 'Mosaic',
libraryTarget: 'var',
},
};
};
const nodeConfig = () => {
const config = commonConfig('node', 'maintained node versions');
return {
...config,
output: {
...config.output,
libraryTarget: 'commonjs2',
},
resolve: {
...config.resolve,
alias: {
...(config.resolve || {}).alias,
scrypt: 'js-scrypt',
},
},
plugins: [
...config.plugins,
new webpack.IgnorePlugin(/^(?:electron|ws)$/),
],
};
};
module.exports = [webConfig, nodeConfig];