import react from '@vitejs/plugin-react' import { defineConfig } from 'vite' import eslint from 'vite-plugin-eslint' function renderChunks(deps: Record) { const chunks = {} Object.keys(deps).forEach((key) => { if ( [ 'react', 'react-router-dom', 'react-dom', '@tiptap/pm', '@types/lodash', ].includes(key) ) return chunks[key] = [key] }) return chunks } //! Create plugin, that creates content type, //! adds mutation, //! loads javascript on page // https://vitejs.dev/config/ export default defineConfig(({ command }) => { if (command === 'build') { return { base: '/wp-content/plugins/fulcrum/apps/wp-wiki/dist/', define: { 'process.env.IS_PREACT': process.env.IS_PREACT, }, plugins: [react()], build: { sourcemap: false, rollupOptions: { output: { manualChunks: { vendor: ['react', 'react-router-dom', 'react-dom'], // '@emotion/react': ['@emotion/react'], '@headlessui': ['@headlessui/react'], '@radix-ui': [ '@radix-ui/react-popover', '@radix-ui/react-select', '@radix-ui/react-toast', ], '@next-ui': ['@nextui-org/react'], // 'body-scroll-lock': ['body-scroll-lock'], // classix: ['classix'], }, }, }, }, } } return { plugins: [react(), eslint()], define: { 'process.env.IS_PREACT': process.env.IS_PREACT, }, test: { globals: true, environment: 'jsdom', }, } })