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!