Skip to content

Commit

Permalink
feat: use vite instead of esbuild directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Oct 2, 2024
1 parent a35bd13 commit 28eaa6e
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 546 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/node": "^20.6.3",
"prettier": "^3.0.2",
"vite": "^5.4.2",
"vite-plugin-singlefile": "^0.13.5",
"vite-plugin-banner": "^0.8.0",
"eslint-plugin-html": "^7.1.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
32 changes: 0 additions & 32 deletions packages/enhanced-typst-svg/esbuild.debug.mjs

This file was deleted.

20 changes: 6 additions & 14 deletions packages/enhanced-typst-svg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,16 @@
"renderer"
],
"repository": "https://github.com/Myriad-Dreamin/typst.ts",
"main": "dist/index.cjs",
"main": "dist/index.js",
"files": [
"index.cjs",
"lib/"
"dist/index.js",
"dist/index.min.js"
],
"directories": {
"lib": "./lib"
},
"peerDependencies": {},
"devDependencies": {
"esbuild": "0.17.19"
},
"scripts": {
"build": "npx tsc",
"debug": "node esbuild.debug.mjs",
"watch": "npx esbuild --watch ./src/index.ts --outfile=dist/index.min.js",
"watch:min": "npx esbuild --watch ./src/index.ts --minify --outfile=dist/index.min.js",
"build:min": "npx esbuild ./src/index.ts --minify --outfile=dist/index.min.js"
"build": "npx tsc && yarn build:max --minify",
"watch": "yarn build:max --watch",
"build:max": "npx vite build"
},
"engines": {
"node": ">=12"
Expand Down
4 changes: 3 additions & 1 deletion packages/enhanced-typst-svg/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"stripInternal": true,

"lib": ["ES5", "ES6", "ES7", "ES2018"]
}
},
"include": ["src/**/*"],
"exclude": ["scripts", "vite.config.js"]
}
10 changes: 10 additions & 0 deletions packages/enhanced-typst-svg/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
build: {
emptyOutDir: false,
lib: {
formats: ['cjs'],
entry: 'src/index.ts',
fileName: 'index.min',
},
},
};
84 changes: 0 additions & 84 deletions packages/tools/esbuild-common.mjs

This file was deleted.

4 changes: 2 additions & 2 deletions packages/tools/wasm-debundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const pkgStats = readdirSync('pkg').map((fileName) => {
// input = new URL('typst_ts_renderer_bg.wasm', import.meta.url)

let replaced = [];
const reg = /input = new URL\('(.+?)', import\.meta\.url\)/mg;
const reg = /module_or_path = new URL\('(.+?)', import\.meta\.url\)/mg;
let exp;
while ((exp = reg.exec(bundleJs))) {
console.log(`Found wasm file name: ${exp[1]}`);
Expand All @@ -40,7 +40,7 @@ const pkgStats = readdirSync('pkg').map((fileName) => {

for (let i = replaced.length - 1; i >= 0; i--) {
const [index, length, wasmFN] = replaced[i];
bundleJs = bundleJs.substring(0, index) + `input = importWasmModule('${wasmFN}', import.meta.url)` + bundleJs.substring(index + length);
bundleJs = bundleJs.substring(0, index) + `module_or_path = importWasmModule('${wasmFN}', import.meta.url)` + bundleJs.substring(index + length);
}

bundleJs = `/// Processed by wasm-debundle.mjs
Expand Down
2 changes: 1 addition & 1 deletion packages/typst.ts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const tsRule = {
files: ['*.ts'],
ignorePatterns: ['esbuild.config.mjs'],
ignorePatterns: ['vite.config.mjs'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
Expand Down
2 changes: 1 addition & 1 deletion packages/typst.ts/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ index.html
*.pdf
*.tsbuildinfo
*.ts.map
esbuild.*
vite.*
.eslint*
84 changes: 0 additions & 84 deletions packages/typst.ts/esbuild.config.mjs

This file was deleted.

11 changes: 4 additions & 7 deletions packages/typst.ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
"!dist/**/all-in-one.bundle.js"
],
"scripts": {
"build-template": "npx vite build --watch -c vite.config.mjs --",
"build-template": "npx vite build -c vite.config.mjs --",
"build:main": "yarn build-template --component=main",
"build:main2": "yarn build-template --component=main2",
"build:canvas-worker": "yarn build-template --component=canvas-worker",
"build": "node scripts/mkdir.mjs && tsc -p ./tsconfig.lib.json && tsc -p ./tsconfig.cjs.json && node scripts/fix-cjs.mjs && node esbuild.config.mjs commonjs production && node esbuild.config.mjs production",
"build:dev": "node scripts/mkdir.mjs && tsc -p ./tsconfig.lib.json && node esbuild.config.mjs",
"build:bundle": "yarn build:main && yarn build-template --component=global-compiler && yarn build-template --component=global-renderer && yarn build-template --component=all-in-one && yarn build-template --component=all-in-one-lite",
"build": "node scripts/mkdir.mjs && tsc -p ./tsconfig.lib.json && tsc -p ./tsconfig.cjs.json && node scripts/fix-cjs.mjs && yarn build:bundle",
"build:dev": "node scripts/mkdir.mjs && tsc -p ./tsconfig.lib.json && npx vite build --watch -c vite.config.mjs -- --component=main",
"prepublish": "turbo build",
"publish:dry": "npm publish --dry-run --access public",
"publish:lib": "npm publish --access public || exit 0"
Expand All @@ -61,8 +60,6 @@
"@myriaddreamin/typst-ts-web-compiler": "*",
"@types/web": "^0.0.99",
"builtin-modules": "3.3.0",
"esbuild": "0.17.19",
"esbuild-plugin-wasm": "^1.1.0",
"tslib": "2.5.2"
}
}
8 changes: 3 additions & 5 deletions packages/typst.ts/src/contrib/all-in-one.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export * from './all-in-one-lite.mjs';
import { $typst, TypstSnippet } from './snippet.mjs';
// @ts-ignore
import typstCompilerData from '../../../compiler/pkg/typst_ts_web_compiler_bg.wasm';
// @ts-ignore
import typstRendererData from '../../../renderer/pkg/typst_ts_renderer_bg.wasm';
import { $typst } from './snippet.mjs';
import typstCompilerData from '../../../compiler/pkg/typst_ts_web_compiler_bg.wasm?url';
import typstRendererData from '../../../renderer/pkg/typst_ts_renderer_bg.wasm?url';

(window as any).$wasm$typst_compiler = typstCompilerData;
(window as any).$wasm$typst_renderer = typstRendererData;
Expand Down
4 changes: 0 additions & 4 deletions packages/typst.ts/src/contrib/canvas-worker-common.mts

This file was deleted.

Loading

0 comments on commit 28eaa6e

Please sign in to comment.