-
I'm building a simple vite plugin for react apps: export const pluginExperiment = () => ({
name: 'plugin-experiment',
config: (config) => {
config.root = 'src'
config.publicDir = '../public'
config.build.outDir = '../dist'
},
}) Which I use like so in import { defineConfig } from 'vite'
import { pluginExperiment } from 'plugin-experiment'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [pluginExperiment(), react()],
}) With the above, running How can I move import react from '@vitejs/plugin-react'
export const pluginExperiment = () => ({
name: 'plugin-experiment',
config: (config) => {
config.root = 'src'
config.publicDir = '../public'
config.build.outDir = '../dist'
},
configResolved: (config) => {
config.plugins.push(react())
},
}) But error during build:
Error: [vite:load-fallback] Could not load /@react-refresh (imported by src/App.jsx): ENOENT: no such file or directory, open '/@react-refresh' While with the following: import react from '@vitejs/plugin-react'
export const pluginExperiment = () => ({
name: 'plugin-experiment',
config: (config) => {
config.root = 'src'
config.publicDir = '../public'
config.build.outDir = '../dist'
},
configResolved: (config) => {
config.plugins = [react, ...config['plugins']]
},
})
Uncaught ReferenceError: React is not defined While this configuration: import react from '@vitejs/plugin-react'
export const pluginExperiment = () => ({
name: 'plugin-experiment',
config: (config) => {
config.root = 'src'
config.publicDir = '../public'
config.build.outDir = '../dist'
},
configResolved: (config) => {
config.plugins = [react(), ...config['plugins']]
},
}) Ends with the following error: Uncaught ReferenceError: $RefreshSig$ is not defined I'm more than a little stumped here, and would appreciate advice on what is happening and how can I fix this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your "plugin function" can return // your plugin code
import type { Plugin, PluginOption } from "vite"
import react from '@vitejs/plugin-react'
export function myPlugin(): PluginOption {
const myActualPlugin: Plugin = {
name: "my-actual-plugin"
}
return [
react(),
myActualPlugin,
];
}
// plugin user code
import { defineConfig } from "vite"
import { myPlugin } from "@my/plugin"
export default defineConfig({
plugins: [myPlugin()]
}); |
Beta Was this translation helpful? Give feedback.
Your "plugin function" can return
PluginOption
, which can be multiplePlugin
s.It would look like this in your case: