-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.common.js
88 lines (83 loc) · 1.79 KB
/
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
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 NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const nodeExternals = require("webpack-node-externals");
let commonConfig = {
entry: path.resolve(__dirname, "../", "src", "index.ts"),
output: {
path: path.resolve(__dirname, "../", "dist"),
globalObject: "this",
library: {
name: "fhenixjs",
type: "umd2",
},
},
resolve: {
extensions: [".ts", ".js"],
},
experiments: {
asyncWebAssembly: true,
topLevelAwait: true,
},
};
let clientConfig = merge(commonConfig, {
target: "web",
module: {
rules: [
{
test: /\.ts?$/,
exclude: [/node_modules/],
use: [{ loader: "ts-loader" }],
},
{
test: /\.wasm$/,
type: "asset/inline",
},
],
},
resolve: {
alias: {
"node-tfhe": "tfhe/tfhe",
},
fallback: {
"tfhe_bg.wasm": require.resolve("tfhe/tfhe_bg.wasm"),
"node-tfhe": require.resolve("tfhe/tfhe"),
},
},
output: {
filename: "browser.js",
},
plugins: [new NodePolyfillPlugin()],
});
const ifdefLoaderOpts = {
DEBUG: true,
version: 3,
};
let serverConfig = merge(commonConfig, {
target: "node",
externalsPresets: { node: true },
output: {
filename: "index.node.js",
},
module: {
rules: [
{
test: /\.ts?$/,
exclude: [/node_modules/],
use: [
{ loader: "ts-loader" },
{ loader: "ifdef-loader", options: ifdefLoaderOpts },
],
},
],
},
externals: [
{
"utf-8-validate": "commonjs utf-8-validate",
bufferutil: "commonjs bufferutil",
"node-tfhe": "commonjs node-tfhe",
},
],
});
module.exports = [clientConfig, serverConfig];