Skip to content

Commit

Permalink
Merge pull request #24 from shuding/auto-entry
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding authored Mar 12, 2023
2 parents e17284b + 6291620 commit bc42373
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tmp
dist/*
!dist/index.d.ts
!dist/asm.d.ts
!dist/auto.d.ts
10 changes: 10 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import initYoga from "./index.js";

const Yoga = await initYoga(
await fetch(new URL("./yoga.wasm", import.meta.url)).then((res) =>
res.arrayBuffer()
)
);

export * from "./yoga/javascript/src_js/generated/YGEnums.js";
export default Yoga;
7 changes: 7 additions & 0 deletions dist/auto.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Yoga } from "./wrapAsm.js";

export * from "./generated/YGEnums.js";
export * from "./wrapAsm.js";

declare const yogaInstance: Yoga;
export default yogaInstance;
10 changes: 10 additions & 0 deletions node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { readFile } from "node:fs/promises";
import { createRequire } from "node:module";
import initYoga from "./index.js";

const Yoga = await initYoga(
await readFile(createRequire(import.meta.url).resolve("./yoga.wasm"))
);

export * from "./yoga/javascript/src_js/generated/YGEnums.js";
export default Yoga;
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"*": {
"asm": [
"dist/asm.d.ts"
],
"auto": [
"dist/auto.d.ts"
]
}
},
Expand All @@ -20,6 +23,11 @@
"./asm": {
"types": "./dist/asm.d.ts",
"default": "./dist/asm.js"
},
"./auto": {
"types": "./dist/auto.d.ts",
"browser": "./dist/browser.js",
"default": "./dist/node.js"
}
},
"scripts": {
Expand Down
16 changes: 10 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ await copyFile("./tmp/yoga.wasm", "./dist/yoga.wasm");

// copy d.ts files
let wrapAsm = await readFile("./yoga/javascript/src_js/wrapAsm.d.ts");
wrapAsm = wrapAsm.toString().replace(/\.\/generated\/YGEnums/g, './generated/YGEnums.js')
await writeFile("./dist/wrapAsm.d.ts", wrapAsm)
wrapAsm = wrapAsm
.toString()
.replace(/\.\/generated\/YGEnums/g, "./generated/YGEnums.js");
await writeFile("./dist/wrapAsm.d.ts", wrapAsm);

await copyFile(
"./yoga/javascript/src_js/generated/YGEnums.d.ts",
Expand All @@ -19,7 +21,7 @@ await copyFile(

export default [
{
input: ["asm.js", "index.js"],
input: ["asm.js", "index.js", "node.js", "browser.js"],
output: {
dir: "dist",
format: "esm",
Expand All @@ -29,9 +31,11 @@ export default [
commonjs({
esmExternals: true,
}),
minify(defineRollupSwcMinifyOption({
compress: { passes: 2 }
}))
minify(
defineRollupSwcMinifyOption({
compress: { passes: 2 },
})
),
],
},
];

0 comments on commit bc42373

Please sign in to comment.