This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
webpack.config.js
74 lines (71 loc) · 1.73 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
const path = require('path');
const portfinder = require('portfinder');
const config = {
entry: ['./src/WebMLPolyfill.js'],
output: {
filename: 'webml-polyfill.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.wasm$/i,
type: 'javascript/auto',
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
configFile: require.resolve('./tsconfig.json'),
compilerOptions: { noEmit: false }
}
}
]
},
resolve: {
extensions: ['.js', '.tsx', '.ts']
},
devServer: {
// enable https
https: process.env.HTTPS === 'true' || false,
// allow connections from LAN
host: '0.0.0.0',
// allow connections using hostname
disableHostCheck: true,
// serve bundle files from /dist/ without writing to disk
publicPath: '/dist/',
},
node: {
fs: 'empty'
}
};
if (process.env.NODE_ENV === 'production') {
config.mode = 'production';
// generate a separate source map file
// exclude it from production server if you don't want to enable source map
config.devtool = 'source-map';
} else {
config.mode = 'development';
// inline the source map in bundle file for remote debugging
config.devtool = 'inline-source-map';
}
module.exports = new Promise((resolve) => {
const basePort = 8080;
portfinder.getPort({
port: basePort
}, (_, port) => {
config.devServer.port = port;
config.devServer.public = `localhost:${port}`;
resolve(config);
});
});