Skip to content

Vite 6: Explore possible improvements #1214

Closed
Closed

Description

@aklinker1

Feature Request

Two parts:

Is your feature request related to a bug?

N/A

What are the alternatives?

N/A

Additional context

https://vite.dev/blog/announcing-vite6.html

Activity

  1. aklinker1 commented on Nov 26, 2024

    @aklinker1
    MemberAuthor

    Wrote a simple test to see how to use the environment APIs to build multiple bundles at once. The API is much nicer to use but performance wise, vite.createBuilder(...).buildApp() negligibly faster than just running vite.build(...) multiple times with different config (what WXT does). Hard to test on a real extension without actually implementing it in WXT... so we'll have to do that to benchmark it against a real extension with lots of dependencies.

    vite-6-demo.zip

    Did not profile memory usage nor did I look into changes to dev mode or importing TS files, so still some work to do.

  2. eMerzh commented on Nov 28, 2024

    @eMerzh

    Hello,

    not sure you had that in your radar, but we were prompted with vite6 dep update, and it seems that the vite (https://wxt.dev/guide/essentials/config/vite.html) method to define the config isn't really type compatible anymore.

    properties like resolve alias & plugins
    🤔

  3. changed the title [-]Vite 6[/-] [+]Explore improvements made possible by Vite 6[/+] on Nov 28, 2024
  4. changed the title [-]Explore improvements made possible by Vite 6[/-] [+]Vite 6: Explore possible improvements[/+] on Nov 28, 2024
  5. aklinker1 commented on Nov 28, 2024

    @aklinker1
    MemberAuthor

    @eMerzh You probably have multiple versions of Vite installed. Type errors like this are usually a sign of this. I just released a new version of WXT that adds support for Vite 6: v0.19.17

    Update WXT, then delete your lockfile or run pnpm i vite@latest && pnpm rm vite to update vite. Then run pnpm why vite again to make sure there's only one version installed in the project. If you use a different package manager... there are similar commands, but I don't know them off the top of my head.

  6. eMerzh commented on Nov 28, 2024

    @eMerzh

    awesome @aklinker1 it makes the trick 💪 thanks

  7. remusris commented on Dec 31, 2024

    @remusris

    A vite template for using React Compiler would be a great addition or at least one example showing how to do it.

  8. aklinker1 commented on Jan 1, 2025

    @aklinker1
    MemberAuthor

    Huh, does the regular react vite plugin not include the compiler already?

  9. remusris commented on Jan 1, 2025

    @remusris

    You have to turn it on and when I tried turning it on it was giving me errors

    image

    https://react.dev/learn/react-compiler

    below was my attempt of integrating it

    import { defineConfig } from 'wxt';
    import { defineRunnerConfig } from 'wxt';
    import { defineWxtModule } from 'wxt/modules';
    
    export interface CustomCommandOptions {
      // Add any options your command needs
      commandName?: string;
    }
    
    // See https://wxt.dev/api/config.html
    export default defineConfig({
      extensionApi: 'chrome',
      modules: ['@wxt-dev/module-react', '@wxt-dev/auto-icons'],
      manifest: {
        permissions: ["activeTab", "scripting", "sidePanel", "storage", "tabs", "history", "unlimitedStorage", "commands"],
        description: "A browser extension that allows you to view and interact with your browser history in a side panel.",
      },
      runner: defineRunnerConfig({
        disabled: true
      }),
      manifestVersion: 3,
      autoIcons: {
        enabled: true,
        grayscaleOnDevelopment: true
      },
      dev: {
        server: {
          port: 5180
        }
      },
      vite: () => ({
        plugins: [
          ['babel-plugin-react-compiler', {}]
        ]
      })
    });
    

    This is the error I was getting

    Type '() => { plugins: {}[][]; }' is not assignable to type '(env: ConfigEnv) => WxtViteConfig | Promise<WxtViteConfig>'.
      Type '{ plugins: {}[][]; }' is not assignable to type 'WxtViteConfig | Promise<WxtViteConfig>'.
        Type '{ plugins: {}[][]; }' is not assignable to type 'WxtViteConfig'.
          Types of property 'plugins' are incompatible.
            Type '{}[][]' is not assignable to type 'PluginOption[]'.
              Type '{}[]' is not assignable to type 'PluginOption'.
                Type '{}[]' is not assignable to type 'PluginOption[]'.
                  Type '{}' is not assignable to type 'PluginOption'.ts(2322)
    types.d.ts(407, 5): The expected type comes from property 'vite' which is declared here on type 'UserConfig'
    
  10. aklinker1 commented on Jan 1, 2025

    @aklinker1
    MemberAuthor

    @remusris See the README for the react module: https://www.npmjs.com/package/@wxt-dev/module-react

    To pass options to the react plugin, like the babel.plugins array, use the react.vite field:

    // wxt.config.ts
    export default defineConfig({
      modules: ['@wxt-dev/module-react'],
      react: {
        vite: {
          babel: {
            plugins: [["babel-plugin-react-compiler", { ... }]
          }
        },
      },
    });
  11. xcaptain commented on Jan 22, 2025

    @xcaptain

    I use

    vite: () => {
        return {
            plugins: [
                tailwindcss(),
            ],
        };
    }

    to load tailwindcss v4, it worked well.

  12. abegehr commented on Jan 28, 2025

    @abegehr

    @xcaptain, for me the new tailwindcss vite plugin (tailwinds v4) is also working in WXT, however I had to use a not-so-fun typecast:

      vite: () => {
        return {
          plugins: [tailwindcss()],
        } as WxtViteConfig;
      },

    Because of typescript throwing Type 'Plugin<any>[]' is not assignable to type 'PluginOption'. - which seems to happen when using different vite versions in one project: vitest-dev/vitest#1706 => would be great to get WXT on latest vite 6 to use with latest plugins like tailwindcss natively.

  13. aklinker1 commented on Jan 28, 2025

    @aklinker1
    MemberAuthor

    @abegehr Working on it. See #1362

  14. ArjixWasTaken commented on Mar 9, 2025

    @ArjixWasTaken

    @xcaptain, for me the new tailwindcss vite plugin (tailwinds v4) is also working in WXT, however I had to use a not-so-fun typecast:

    vite: () => {
    return {
    plugins: [tailwindcss()],
    } as WxtViteConfig;
    },

    Because of typescript throwing Type 'Plugin<any>[]' is not assignable to type 'PluginOption'. - which seems to happen when using different vite versions in one project: vitest-dev/vitest#1706 => would be great to get WXT on latest vite 6 to use with latest plugins like tailwindcss natively.

    a less ugly way is to do

        vite: () => <WxtViteConfig>({
            plugins: [tailwindcss()],
        }),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions