forked from VALIS-software/valis-hpgv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
83 lines (70 loc) · 2.36 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 webpack = require("webpack");
// output settings
const buildName = 'valis-hpgv';
module.exports = (env, argv) => {
env = env || {};
let releaseMode = argv.mode === 'production';
const config = {
mode: releaseMode ? "production" : "development",
context: path.resolve(__dirname, "src"),
entry: "./index",
output: {
path: path.join(__dirname, "dist"),
filename: env.includeReact ? `${buildName}.js` : `${buildName}.react-peer.js`,
library: '',
libraryTarget: 'umd',
},
devServer: {
publicPath: '/dist',
},
// Enable sourcemaps for debugging webpack's output.
devtool: releaseMode ? "source-map" : "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
{
test: /\.(ts|tsx)$/,
loader: "ts-loader",
exclude: [path.resolve(__dirname, "node_modules")],
},
// convert binary files into data-urls and embed into the output
{
test: /\.bin/,
loader: 'url-loader'
},
// css are loaded as strings
{
test: /\.css/,
loader: 'text-loader'
}
]
},
plugins: [
// pass --env to javascript build via process.env
new webpack.DefinePlugin({ "process.env": JSON.stringify(env) }),
].concat(
// add bundle analyzer plugin if flag is set
env.analyze ? [new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)] : []
),
externals: env.includeReact ? {} : {
// don't bundle react or react-dom
'react': {
commonjs: "react",
commonjs2: "react",
amd: "React",
root: "React"
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "ReactDOM",
root: "ReactDOM"
}
}
}
return config;
};