fix: Android 上強制使用 @rollup/wasm-node

This commit is contained in:
CrescentLeaf
2025-09-13 12:28:02 +08:00
parent 633cfed87b
commit 1deec533ad
3 changed files with 43 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
import process from 'node:process'
import child_process from 'node:child_process'
import fs from 'node:fs/promises'
function spawn(exec: string, args: string[]) {
child_process.spawnSync(exec, args, {
stdio: [process.stdin, process.stdout, process.stderr]
})
}
function runBuild() {
const args = [
"run",
"-A",
"--node-modules-dir",
]
let i = 0
for (const arg of process.argv) {
if (i > 1)
args.push(arg)
i++
}
spawn('deno', args)
}
if (process.platform == 'android') {
try {
await fs.stat('./node_modules/.deno/rollup@4.50.1/node_modules/rollup/')
} catch (e) {
spawn('deno', ['install', '--node-modules-dir=auto'])
}
spawn('sh', ["fix-build-on-android.sh"])
}
runBuild()

View File

@@ -1,7 +1,7 @@
{
"tasks": {
"build": "deno run -A --node-modules-dir npm:vite build",
"build-watch": "deno run -A --node-modules-dir npm:vite --watch build"
"build": "deno run --allow-run --allow-env --allow-read checkIsAndroidAndBuild.ts npm:vite build",
"build-watch": "deno run --allow-run --allow-env --allow-read checkIsAndroidAndBuild.ts npm:vite --watch build"
},
"compilerOptions": {
"lib": ["ES2022", "DOM", "DOM.Iterable"],
@@ -18,6 +18,8 @@
"react-dom": "npm:react-dom@18.3.1",
"vite": "npm:vite@7.0.6",
"rollup": "npm:@rollup/wasm-node@4.48.0",
"chalk": "npm:chalk@5.4.1",
"mdui": "npm:mdui@2.1.4",

View File

@@ -0,0 +1,3 @@
rm -r ./node_modules/.deno/rollup@4.50.1/node_modules/rollup/
cp -r ./node_modules/.deno/@rollup+wasm-node@4.48.0/node_modules/@rollup/wasm-node/ node_modules/.deno/rollup@4.50.1/node_modules/rollup/
echo Replaced rollup with @rollup/wasm-node successfully