如何在Unity中使用npm包运行Typescript代码?

问题描述 投票:0回答:1

我想在 Unity 中运行使用 npm 包的 ts 文件。有什么办法可以做到吗?

还需要 tsconfig 编译器设置:

{
    "compilerOptions": {
        "target": "es2020",
        "module": "es2022",
        "lib": ["dom", "esnext"],
        "outDir": "./build",
        "rootDir": ".",
        "strict": true,
        "strictPropertyInitialization": false,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "esModuleInterop": true,
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "allowJs": true,
        "declaration": true,
        "sourceMap": true,
        "noFallthroughCasesInSwitch": true,
        "allowSyntheticDefaultImports": true
    },
    "include": ["./src"]
}
javascript typescript unity-game-engine
1个回答
0
投票

通过运行,如果您的意思是通过 cli 并且仅使用单个文件,则使用

tsx
包并运行
(npx | yarn | pnpm) tsx <path-to-file>.ts

它就像 ts-node 但要好得多

GitHub 存储库

如果您指的是浏览器中的整个存储库,请使用 tsup 输出 dist 目录,然后可以使用

node ./dist/index.js
启动该目录。如果使用
tsup.config.ts
文件,请务必设置 --dts 标志或字段。

鉴于您的问题中提供的上下文有些有限,我可以建议这两个选项

© www.soinside.com 2019 - 2024. All rights reserved.