-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(vite): Use app/lib tsconfig for buildable paths resolution #19972
feat(vite): Use app/lib tsconfig for buildable paths resolution #19972
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 507ff07. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 6 targets
Sent with 💌 from NxCloud. |
14f1fe7
to
34bd768
Compare
projectRoot, | ||
dependencies | ||
); | ||
process.env.NX_TSCONFIG_PATH = tmpTsConfigPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When options.buildLibsFromSource === true
, process.env.NX_TSCONFIG_PATH
would be undefined. Is that desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's expected - process.env.NX_TSCONFIG_PATH
would also be undefined during test
or serve
in case of app.
so the consumer would have to always check it like:
const tsconfigPath = process.env.NX_TSCONFIG_PATH ?? join(__dirname, 'tsconfig.lib.json')
whether it's desired I'm not that certain - it seems to me to be better for consumers than doing something like:
const tmpTsconfigPath = join(
workspaceRoot,
'tmp',
projectRootFromWorkspaceRoot,
'tsconfig.generated.json'
)
const tsconfigPath = existsSync(tmpTsconfigPath) ? tmpTsconfigPath : join(__dirname, 'tsconfig.lib.json')
both of these are leaking implementation details, but the first one is a little less leaky imho
Can anyone please check this PR? It is currently blocking us from Vite adoption in our project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure I'll approve this! Thanks for the PR!
@pulecka @belaczek I cannot force-push on your branch. Can you please check the "allow commits by maintainers": https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork |
@belaczek you either need to rebase with |
This change uses actual project TypeScript config - i.e. `tsconfig.app.json` or `tsconfig.lib.json` - to generate temporary `tsconfig` when building with `"buildLibsFromSource": false` option. This is needed when users would want to use the generated `tsconfig` in their Vite configuration - e.g. for generating type declarations. Also exposed the generated `tsconfig` via `NX_TSCONFIG_PATH` env variable. This way users trying to use the generated config don't have to know & depend on specific path which feels like an internal implementation detail. So now user can use `vite-plugin-dts` or `@rollup/plugin-typescript` to generate type declarations during build: ``` export default defineConfig({ plugins: [ nxViteTsPaths(), { ...typescript({ tsconfig: process.env.NX_TSCONFIG_PATH ?? join(__dirname, 'tsconfig.lib.json'), noForceEmit: true, }), apply: 'build', }, ], }) ```
34bd768
to
507ff07
Compare
@mandarini @belaczek rebased with latest master. |
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
This change uses actual project TypeScript config - i.e.
tsconfig.app.json
ortsconfig.lib.json
- to generate temporarytsconfig
file when building with"buildLibsFromSource": false
option.This is needed when users would want to use the generated
tsconfig
in their Vite configuration - e.g. for generating type declarations.Also exposed the generated
tsconfig
viaNX_TSCONFIG_PATH
env variable. This way users trying to use the generated config don't have to know & depend on specific path which feels like an internal implementation detail.So now user can use
vite-plugin-dts
or@rollup/plugin-typescript
to generate type declarations during build:Current Behavior
Generated temporary
tsconfig
file is based on projecttsconfig.json
file which is shared in typical NX setups for tests & build. And as such it is missing some options that are relevant only for build - e.g.emitDeclarationOnly
.