import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; /** * Separate Vite config for the Gutenberg editor sidebar plugin. * Externalizes all @wordpress/* packages since WP provides them. * Build: npx vite build --config vite.config.editor.ts */ export default defineConfig({ plugins: [ react({ // Use WordPress's React, not our own jsxRuntime: "classic", jsxImportSource: undefined, }), ], build: { outDir: "build", emptyOutDir: false, // Don't delete the admin bundle lib: { entry: "src/editor/index.tsx", name: "ViralyEditor", fileName: () => "viraly-editor.js", formats: ["iife"], }, rollupOptions: { external: [ "@wordpress/plugins", "@wordpress/edit-post", "@wordpress/element", "@wordpress/components", "@wordpress/data", "react", "react-dom", ], output: { globals: { "@wordpress/plugins": "wp.plugins", "@wordpress/edit-post": "wp.editPost", "@wordpress/element": "wp.element", "@wordpress/components": "wp.components", "@wordpress/data": "wp.data", react: "wp.element", "react-dom": "wp.element", }, }, }, }, define: { "process.env.NODE_ENV": JSON.stringify("production"), }, });