Skip to content
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

Export configured Vite plugins from packages/build #43847

Merged
merged 7 commits into from
Jul 9, 2024

Conversation

gzdunek
Copy link
Contributor

@gzdunek gzdunek commented Jul 4, 2024

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 in packages/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:

  1. Importing the plugins via relative paths (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.
  2. Using workspace imports fixed that issue, but I couldn't make it work with TypeScript. I was getting errors as below: 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.

@gzdunek gzdunek added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v15 backport/branch/v16 labels Jul 4, 2024
@github-actions github-actions bot requested review from avatus and rudream July 4, 2024 11:29
@gzdunek gzdunek removed request for avatus and rudream July 4, 2024 11:32
web/packages/build/vite/tsconfigPaths.mjs Outdated Show resolved Hide resolved
@gzdunek
Copy link
Contributor Author

gzdunek commented Jul 8, 2024

Friendly ping @ryanclark

Copy link
Contributor

@ryanclark ryanclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation for removing TypeScript? Can we use .mts instead?

web/packages/build/vite/react.mjs Outdated Show resolved Hide resolved
@gzdunek
Copy link
Contributor Author

gzdunek commented Jul 8, 2024

What's the motivation for removing TypeScript? Can we use .mts instead?

I wasn't able to import TS files from a build workspace (please take a look at the point 2. in the PR description). I tried .mts too, but with no luck, I think we would have to use a custom module loader (like ts-node) to be able to load a TS file :/
This should be probably fixed on Vite side, since it can load TS files imported through relative imports.

@ryanclark
Copy link
Contributor

(please take a look at the point 2. in the PR description)

Yep, my bad

@gzdunek gzdunek added this pull request to the merge queue Jul 9, 2024
Merged via the queue into master with commit 503afcf Jul 9, 2024
38 checks passed
@gzdunek gzdunek deleted the gzdunek/vite-plugins-in-build branch July 9, 2024 12:42
@public-teleport-github-review-bot

@gzdunek See the table below for backport results.

Branch Result
branch/v15 Create PR
branch/v16 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v15 backport/branch/v16 no-changelog Indicates that a PR does not require a changelog entry size/sm ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants