javascript Anguel 17 SSR -如何将服务器文件(*.mjs)编译为 *.js

jgzswidk  于 5个月前  发布在  Java
关注(0)|答案(2)|浏览(100)

我的主机提供商要求将服务器文件编译为CommonJs,默认情况下Angular17将文件编译为模块JS .mjs*,我尝试更改tsconfig.json,但它会更改整个应用程序的作用域,但我只想更改服务器文件。我一直在寻找如何使用tsconfig.server.json之类的文件,但我不知道以后如何将其拆分为angular.json文件.
如何在Angular 17中将 *.mjs文件转换为SSR的 *.js文件?


的数据
默认tsconfig.json文件:

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "declaration": false,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": ["ES2022", "dom"]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

字符串

h22fl7wq

h22fl7wq1#

我找到了一个解决方案(但不是如何更改它的解决方案),如果您的提供程序需要 *.js文件来运行Angular应用程序,您可以简单地创建特定的文件,例如app.js,然后在此文件中写入:

import ('<path-to-your-dist-mjs-file>.mjs');

字符串
就是这样,它会从该文件加载你的Angular应用程序。它适用于我的MyDevil托管提供商Passenger。我希望它能有所帮助。

yh2wf1be

yh2wf1be2#

您应该使用@angular-devkit/build-angular NPM包中包含的browser-esbuild构建器,因为Angular现在默认使用 application 构建器

相关问题