最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nx monorepo - NX Generators - Set module to "ESNext" instead of "commonjs" in tsconfig.json

programmeradmin0浏览0评论

I want to create an NX generator to ensure that newly generated projects e.g. of type @nx/js:library have their compilerOptions module value set to "ESNext" and not "commonjs" at creation.

I tried adding the following generator to my nx.json file (without success):

"generators": {
    "@nx/js:library": {
        "compilerOptions": {
            "module": "ESNext"
        }
    }
}

I continue to generate the nx project using:

NX  Generating @nx/js:library

UPDATE package.json
CREATE libs/test/tsconfig.lib.json
CREATE libs/test/tsconfig.json
CREATE libs/test/src/index.ts
CREATE libs/test/src/lib/test.spec.ts
CREATE libs/test/src/lib/test.ts
CREATE libs/test/README.md
CREATE libs/test/package.json
UPDATE nx.json
CREATE libs/test/project.json
CREATE libs/test/.eslintrc.json
CREATE libs/test/jest.config.ts
CREATE libs/test/tsconfig.spec.json
UPDATE tsconfig.base.json

UPDATE nx.json*  Executing task: npx nx generate @nx/js:library libs/test --name=test --no-interactive --dry-run

The outcome of the generated project's tsconfig.json always ends up with "module": "commonjs":

{
    "extends": "../../tsconfig.base.json",
    "compilerOptions": {
        "module": "commonjs",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "noImplicitOverride": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "noPropertyAccessFromIndexSignature": true
    },
    "files": [],
    "include": [],
    "references": [
        {
            "path": "./tsconfig.lib.json"
        },
        {
            "path": "./tsconfig.spec.json"
        }
    ]
}

The tsconfig.base.json file do have "module" set to "ESNext". Maybe this does not make a difference, but I want to clarify it is not set to "commonjs" in the base tsconfig file.

How can I achieve what I wish for? Thanks!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论