-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
45 lines (38 loc) · 995 Bytes
/
webpack.common.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
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HTMLPlugin = require('html-webpack-plugin')
const { DefinePlugin } = require('webpack')
const { resolve } = require('path')
module.exports = [true, false].map((useWasm) => ({
entry: './src/main.ts',
output: {
filename: `${useWasm ? 'wasm' : 'javascript'}.[contenthash:6].js`,
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js', '.wasm'],
alias: {
mandelbrot: resolve(__dirname, 'pkg'),
},
},
plugins: [
new CopyWebpackPlugin([
{ from: '*', context: './assets/' },
]),
new DefinePlugin({
USE_WASM: JSON.stringify(useWasm),
}),
new HTMLPlugin({
title: `${useWasm ? 'WebAssembly' : 'JavaScript'} Mandelbrot Generator`,
filename: useWasm ? 'wasm.html' : 'javascript.html',
template: './src/index.html',
}),
],
}))