Skip to content

Commit dceb23f

Browse files
committed
v.1.2.12 fix output file react imports
1 parent 0fdf340 commit dceb23f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spacesvr",
3-
"version": "1.2.11",
3+
"version": "1.2.12",
44
"private": true,
55
"description": "An Environment for WebXR Spaces",
66
"keywords": [

rollup.config.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from "path";
21
import { promises as fs } from "fs";
32
import babel from "rollup-plugin-babel";
43
import resolve from "rollup-plugin-node-resolve";
@@ -38,9 +37,21 @@ function targetTypings(entry, out) {
3837
}
3938

4039
function addReactImport(out) {
40+
const text = out.includes("cjs")
41+
? `var React = require('react');\n`
42+
: `import React from "react";\n`;
43+
4144
return {
4245
writeBundle() {
43-
return fs.appendFile(`dist/${out}`, `import React from "react";`);
46+
return fs.lstat(`dist/${out}`).then(async () => {
47+
const data = await fs.readFile(`dist/${out}`);
48+
const fd = await fs.open(`dist/${out}`, "w+");
49+
// eslint-disable-next-line no-undef
50+
const insert = new Buffer.from(text);
51+
await fd.write(insert, 0, insert.length, 0);
52+
await fd.write(data, 0, data.length, insert.length);
53+
await fd.close();
54+
});
4455
},
4556
};
4657
}

0 commit comments

Comments
 (0)