Export configured Vite plugins from packages/build
#43847
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, both Web UI and Connect import plugin configs from
packages/build
and then provide them to plugins they import. This will no longer work after the migration to pnpm, because the plugins are installed inpackages/build
, so they are not available outside that package.Instead of moving them to the root, we can export configured plugins from
packages/build
, reducing the code duplication.Unfortunately, it turned out to be more difficult than I thought:
import { reactPlugin } from '../build/vite/react'
) didn't work, because the plugin packages (like@vitejs/plugin-react-swc
) were resolved in context of a final package (like teleterm or teleport) so Node.js couldn't find them in node_modules.TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/grzegorz/code/teleport/web/packages/build/vite/tsconfigPaths.ts
I tried different options, importing with no extension, with
.mts
etc, but with no luck.AFAIK the only way to solve it is to use
ts-node
or something to allow Node.js resolve TS imports. However, this is too much work. Because our plugins are very simple, I decided to convert them to JS, I don't think we will lose much on this.There is a long issue about this problem in Vite.