-
Notifications
You must be signed in to change notification settings - Fork 18
/
webpack.config.js
91 lines (82 loc) · 2.21 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
const path = require('path');
const webpack = require('webpack');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const {merge} = require('webpack-merge');
const packageData = require('./package.json');
const prodConfig = require('./webpack.prod');
const devConfig = require('./webpack.dev');
const {ProgressPlugin, DefinePlugin} = webpack;
const distPath = path.resolve(__dirname, 'dist');
const srcPath = path.resolve(__dirname, 'src');
module.exports = () => {
const isProductionEnv = process.env.NODE_ENV === 'production';
let nodeConfig = {
target: 'node',
externals: [nodeExternals()],
output: {
filename: 'node.js',
libraryTarget: 'commonjs2',
libraryExport: 'default'
}
};
let browserConfig = {
target: 'web',
output: {
filename: 'browser.js',
libraryTarget: 'umd',
umdNamedDefine: true,
libraryExport: 'default',
globalObject: 'this',
library: 'StarkExAPI'
},
resolve: {
fallback: {
http: false,
https: false
}
}
};
const commonConfig = {
context: srcPath,
entry: './index.ts',
output: {
path: distPath
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
include: [srcPath],
exclude: [/node_modules/]
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
watchOptions: {
aggregateTimeout: 600,
ignored: /node_modules/
},
plugins: [
new ProgressPlugin(),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [distPath]
}),
new DefinePlugin({
__VERSION__: JSON.stringify(packageData.version),
__NAME__: JSON.stringify(packageData.name),
__NODE_ENV__: JSON.stringify(process.env.NODE_ENV)
})
]
};
nodeConfig = merge(nodeConfig, commonConfig);
browserConfig = merge(browserConfig, commonConfig);
if (isProductionEnv) {
return [merge(nodeConfig, prodConfig), merge(browserConfig, prodConfig)];
}
return [merge(nodeConfig, devConfig), merge(browserConfig, devConfig)];
};