-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
84 lines (77 loc) · 1.88 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
/* global __dirname, require, module */
const path = require('path')
const webpack = require('webpack')
const env = require('yargs').argv.env // use --env with webpack 2
const banner = require('./license.js');
const copyPlugin = require('copy-webpack-plugin')
const libraryName = 'lxly'
let mode = 'development'
if (env === 'build') {
mode = 'production'
}
const clientConfig = {
mode,
devtool: 'source-map',
entry: `${__dirname}/src/index.ts`,
target: 'web',
output: {
path: `${__dirname}/dist`,
filename: `${libraryName}.umd${mode === 'production' ? '.min' : ''}.js`,
library: libraryName,
libraryTarget: 'umd',
// libraryExport: 'default',
umdNamedDefine: true,
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
externals: {
web3: 'web3',
'@ethereumjs/util': '@ethereumjs/util',
'assert': 'assert',
'buffer': 'buffer',
'node-fetch': 'node-fetch',
'stream': 'stream'
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.json', '.js', '.ts', 'tsx'],
},
plugins: [
new copyPlugin({
patterns: [{ from: path.resolve('build_helper', 'npm.export.js'), to: '' }],
}),
new webpack.BannerPlugin(banner)
],
}
const serverConfig = {
...clientConfig,
target: 'node',
output: {
path: `${__dirname}/dist`,
filename: `${libraryName}.node${mode === 'production' ? '.min' : ''}.js`,
// globalObject: 'this',
libraryTarget: 'commonjs2',
},
plugins: [
new webpack.DefinePlugin({
'process.env.BUILD_ENV': JSON.stringify("node")
}),
]
}
const standaloneConfig = {
...clientConfig,
output: {
...clientConfig.output,
library: libraryName,
filename: `${libraryName}.js`,
},
externals: {},
}
module.exports = [clientConfig, serverConfig, standaloneConfig]