Skip to content

Commit 04d0265

Browse files
committed
fix: commonjs default export (fixes #14)
1 parent 5e2a308 commit 04d0265

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- fix: commonjs default export (fixes [#14](https://github.com/vitejs/vite-plugin-react-swc/issues/14))
6+
37
## 3.0.0
48

59
This is plugin is now stable! 🎉

scripts/bundle.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ rmSync("dist", { force: true, recursive: true });
1111

1212
const serverOptions: BuildOptions = {
1313
bundle: true,
14-
entryPoints: ["src/index.ts"],
1514
platform: "node",
1615
target: "node14",
1716
legalComments: "inline",
@@ -31,8 +30,24 @@ Promise.all([
3130
legalComments: "inline",
3231
watch: dev,
3332
}),
34-
build({ ...serverOptions, outfile: "dist/index.cjs" }),
35-
build({ ...serverOptions, format: "esm", outfile: "dist/index.mjs" }),
33+
build({
34+
...serverOptions,
35+
stdin: {
36+
contents: `import react from "./src";
37+
module.exports = react;
38+
// For backward compatibility with the first broken version
39+
module.exports.default = react;`,
40+
resolveDir: ".",
41+
},
42+
outfile: "dist/index.cjs",
43+
logOverride: { "empty-import-meta": "silent" },
44+
}),
45+
build({
46+
...serverOptions,
47+
entryPoints: ["src/index.ts"],
48+
format: "esm",
49+
outfile: "dist/index.mjs",
50+
}),
3651
]).then(() => {
3752
execSync("cp LICENSE README.md dist/");
3853

0 commit comments

Comments
 (0)