-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
111 lines (105 loc) · 2.17 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import WasmPackPlugin from '@wasm-tool/wasm-pack-plugin';
import path from 'path';
import { fileURLToPath } from 'url';
import CopyPlugin from 'copy-webpack-plugin';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const dist = path.resolve(__dirname, 'dist');
const distLib = path.resolve(dist, 'lib');
const distCjs = path.resolve(dist, 'cjs');
const config = {
name: 'web',
mode: 'development',
context: path.resolve(__dirname, 'js'),
entry: {
index: './index'
},
devtool: 'source-map',
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
output: {
path: dist,
filename: 'index.js',
chunkFormat: 'module',
library: {
type: 'module'
}
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader'
},
exclude: [/node_modules/, path.resolve(__dirname, 'examples')]
},
{
test: /\.wasm$/,
type: 'asset/inline'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
externals: {
'node:crypto': 'commonjs2 node:crypto'
},
devServer: {
static: dist
},
experiments: {
asyncWebAssembly: true,
outputModule: true
},
plugins: [
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, 'js/bridge'),
outDir: distLib,
extraArgs: '--target web',
outName: 'lib',
forceMode: 'production'
})
],
target: 'web'
};
const webTarget = config;
const webSingleFileTarget = {
...config,
name: 'web-single-file',
dependencies: ['web'],
output: {
path: dist,
filename: 'blyss-bundle.min.js',
library: {
type: 'window',
name: 'blyss'
}
}
};
const nodeTarget = {
...config,
name: 'node',
dependencies: ['web'],
output: {
path: dist + '/cjs',
filename: 'index.cjs',
library: {
type: 'commonjs'
}
},
externals: {},
experiments: {
asyncWebAssembly: true
},
target: 'node',
plugins: [
new CopyPlugin({
patterns: [{ from: '../cjs-package.json', to: distCjs + '/package.json' }]
})
]
};
export default [webTarget, webSingleFileTarget, nodeTarget];