forked from wavesplatform/signer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
83 lines (75 loc) · 2.17 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
const path = require('path');
const merge = require('webpack-merge'); // делает deep merge конфигов
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { EnvironmentPlugin } = require('webpack');
const NODE_ENV = process.env.NODE_ENV
const PATHS = {
root: path.resolve(__dirname),
dist: path.resolve('./dist')
}
const commonConfig = (mode) => merge([{
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: [
/node_modules/,
path.join(PATHS.root, 'test')
],
options: {
transpileOnly: true
}
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
modules: ['node_modules'],
},
output: {
library: 'signer',
libraryTarget: 'umd',
globalObject: 'this',
path: PATHS.dist,
filename: '[name].js'
},
plugins: [
new ForkTsCheckerWebpackPlugin({
tsconfig: path.join(PATHS.root, 'tsconfig.build.json')
}),
new EnvironmentPlugin(['NODE_ENV'])
],
mode
}]);
const plugins = ({ ba }) => ({
plugins: [
ba && new BundleAnalyzerPlugin()
].filter(Boolean)
})
const entry = (name) => ({
entry: { [name]: path.join(PATHS.root, 'src', 'index.ts') }
})
module.exports = (env = {}) => {
const mode = NODE_ENV
const pluginsConfig = {
ba: env.ba // pass --env.ba to enable bundle analyzer
}
if (mode === 'production') {
return merge([
commonConfig(mode),
entry('signer.min'),
plugins(pluginsConfig),
]);
} else if (mode === 'development') {
return merge([
commonConfig(mode),
entry('signer'),
plugins(pluginsConfig),
{ devtool: 'inline-source-map' },
]);
} else {
throw new Error(`Unexpected mode provided: ${mode}. Must be one of ['development', 'production']`);
}
};