-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
69 lines (56 loc) · 1.43 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
const [server, client] = require("nullstack/webpack.config");
const path = require("path");
function swc(options, other) {
const config = {
test: other.test,
use: {
loader: require.resolve("swc-loader"),
options: { jsc: {}, env: {} },
},
};
if (options.target === "server") {
config.use.options.env.targets = { node: process.versions.node };
} else {
config.use.options.env.targets = "defaults";
}
config.use.options.jsc.parser = {
syntax: other.syntax,
exportDefaultFrom: true,
};
if (other.template) {
config.use.options.jsc.parser[other.template] = true;
}
config.use.options.jsc.transform = {
// react: {
// throwIfNamespace: true,
// },
};
return config;
}
function js(options) {
return swc(options, {
test: /.*react\/.*\.(js|jsx)$/,
syntax: "ecmascript",
template: "jsx",
});
}
function ts(options) {
return swc(options, {
test: /.*react\/.*\.(ts|tsx)$/,
syntax: "typescript",
template: "tsx",
});
}
function customClient(...args) {
const config = client(...args);
config.module.rules.push(js({ target: "client" }));
config.module.rules.push(ts({ target: "client" }));
return config;
}
function customServer(...args) {
const config = server(...args);
config.module.rules.push(js({ target: "server" }));
config.module.rules.push(ts({ target: "server" }));
return config;
}
module.exports = [customServer, customClient];