-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
webpack.config.cjs
132 lines (115 loc) · 3.46 KB
/
webpack.config.cjs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const path = require("node:path");
const { DefinePlugin } = require("webpack");
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin");
const { merge } = require("webpack-merge");
function getBasicConfig() {
return {
experiments: {
outputModule: true
},
externals: [],
externalsType: "module",
module: {
rules: [
{
test: /\.[jt]s$/,
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: ["> 0.25%, not dead", "maintained node versions"]
}
],
"@babel/preset-typescript"
],
plugins: ["babel-plugin-transform-async-to-promises"]
},
resolve: {
fullySpecified: false
}
}
]
},
node: false,
output: {
environment: {
module: true
},
library: {
type: "module"
}
},
resolve: {
alias: {
// http: path.resolve(__dirname, "./util/http.stub.ts"),
// https: path.resolve(__dirname, "./util/http.stub.ts")
// "node-fetch": path.resolve(__dirname, "./util/node-fetch.stub.ts")
},
extensions: [".js"],
fallback: {
buffer: false,
crypto: false,
dns: false,
fs: false,
http: false,
https: false,
module: false,
net: false,
path: false,
stream: false,
util: false
}
}
};
}
module.exports = [
merge(getBasicConfig(), {
entry: path.resolve(__dirname, "./source/index.ts"),
output: {
filename: "index.js",
path: path.resolve(__dirname, "./dist/web")
},
plugins: [
new DefinePlugin({
TARGET: JSON.stringify("web")
})
],
resolve: {
alias: {
entities: path.resolve(__dirname, "./util/entities.stub.ts"),
"node-fetch": path.resolve(__dirname, "./util/node-fetch.stub.ts")
},
plugins: [
// Handle .ts => .js resolution
new ResolveTypeScriptPlugin()
]
},
target: "web"
}),
merge(getBasicConfig(), {
entry: path.resolve(__dirname, "./source/index.ts"),
externals: ["entities"],
output: {
filename: "index.js",
path: path.resolve(__dirname, "./dist/react-native"),
chunkFormat: "commonjs"
},
plugins: [
new DefinePlugin({
TARGET: JSON.stringify("react-native")
})
],
resolve: {
alias: {
"node-fetch": path.resolve(__dirname, "./util/node-fetch.stub.ts")
},
plugins: [
// Handle .ts => .js resolution
new ResolveTypeScriptPlugin()
]
},
target: "web"
})
];