-
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): add tsconfig paths resolution plugin #17844
feat(vite): add tsconfig paths resolution plugin #17844
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit ce7876d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
948e075
to
e698e4c
Compare
e698e4c
to
694577d
Compare
694577d
to
f9a319a
Compare
f9a319a
to
1a271ee
Compare
1a271ee
to
12b029f
Compare
12b029f
to
d1849c8
Compare
d1849c8
to
9510617
Compare
9510617
to
94ef222
Compare
94ef222
to
8d06002
Compare
8d06002
to
e931bdb
Compare
try { | ||
resolvedFile = matchTsPathEsm(source); | ||
} catch (e) { | ||
logIt('Using fallback path matching.'); | ||
resolvedFile = matchTsPathFallback?.(source); | ||
} |
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.
This solves the issues I came across where a default @nx/js library will be built with the following package.json
{
"name": "@acme/js-lib",
"version": "0.0.1",
"type": "module",
"peerDependencies": {
"tslib": "2.6.0"
},
"main": "./src/index.js",
"types": "./src/index.d.ts"
}
and vite will be unable to load it as RollUp claims it cannot find the named exports, or the tsconfig-paths
will not be able to resolve the exports object since it doesn't exist.
The same issue happens in the original plugin being used as well vite-tsconfig-paths
.
This fallbacks to the root level tsconfig where the .ts
files will be loaded instead so projects that don't include export
objects or commonjs will still be able to be used in the project with buildLibsFromSource=false
just will be forced to be build from source.
This can be fixed in the userland by changing the tsconfig settings to use NodeNext and type:module
in package.json which allows vite to see the named exports
i.e. the output switches from
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./lib/lib-js"), exports);
//# sourceMappingURL=index.js.map
to just
export * from './lib/lib-js';
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.
@jaysoo would like your opinion on this, to see if this makes sense or if we should see what we can do to get cjs built libs working inside vite.
packages/vite/src/migrations/update-16-5-0-change-ts-paths-plugin/change-ts-paths-plugin.ts
Outdated
Show resolved
Hide resolved
registerTsConfigPaths(tmpTsConfig); | ||
} else { | ||
registerTsConfigPaths(tsConfig); |
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.
As far as I can tell, since these paths never being used by vite downstream, there isn't a reason to register them anymore.
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.
Interesting, and thank you @barbados-clemens !! I'm going to test this out today. I am thinking, should we really drop the use of vite-tsconfig-paths
plugin, and rely only on the tsconfig-paths
? I'm thinking that maybe vite-tsconfig-paths
covers some specific use cases for vite, and using vite-tsconfig-paths
in the nx-vite-paths
plugin (instead of tsconfig-paths
) could potentially save us some maintenance? Again, have not tried out the PR yet, will do today, and not sure what more vite-tsconfig-paths does, so I'm just speculating!
In any case, I'll test it out today! :D thanks!
I also want to see @jaysoo opinion!
Cool! So, yes, I tested on this repo: https://github.com/mandarini/vite-paths/tree/test-caleb on the branch |
packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap
Show resolved
Hide resolved
09e1803
to
2c4a5bd
Compare
2c4a5bd
to
f549328
Compare
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.
Approving to move this forward, but still would like one look from @jaysoo
f549328
to
a148904
Compare
a148904
to
8dd49df
Compare
8dd49df
to
8ba6349
Compare
8ba6349
to
e0eafcf
Compare
e0eafcf
to
ce7876d
Compare
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. |
Current Behavior
vite-tsconfig-paths plugin isn't able to work with tmp tsconfigs to make incremental building work
Expected Behavior
nx supports incremental building with vite
Related Issue(s)
TODO:
Fixes #