forked from webmachinelearning/webnn-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (85 loc) · 2 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
const path = require('path');
const portfinder = require('portfinder');
const TerserPlugin = require("terser-webpack-plugin");
const config = {
entry: ['./src/main.js'],
output: {
filename: 'webnn-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'
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
typeofs: false,
},
},
}),
],
},
};
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);
});
});