2023-01-10 11:24:24 +00:00
|
|
|
import react from '@vitejs/plugin-react-swc'
|
2024-09-25 15:17:58 +00:00
|
|
|
import { preserveDirectives } from 'rollup-plugin-preserve-directives'
|
2023-01-10 11:24:24 +00:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
2024-09-25 15:17:58 +00:00
|
|
|
import { dependencies, devDependencies, peerDependencies } from './package.json'
|
2023-01-10 11:24:24 +00:00
|
|
|
|
2023-03-13 21:52:43 +00:00
|
|
|
const external = [
|
|
|
|
...Object.keys(dependencies || {}),
|
|
|
|
...Object.keys(peerDependencies || {}),
|
2024-09-25 15:17:58 +00:00
|
|
|
...Object.keys(devDependencies || {}),
|
2023-03-13 21:52:43 +00:00
|
|
|
].map(name => new RegExp(`^${name}(/.*)?`))
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
return {
|
|
|
|
build: {
|
|
|
|
target: 'es2020',
|
|
|
|
lib: {
|
2024-09-25 15:17:58 +00:00
|
|
|
entry: {
|
|
|
|
'src/index': './src/index.tsx',
|
|
|
|
'tailwind.config': './tailwind.config.ts',
|
|
|
|
},
|
2023-03-13 21:52:43 +00:00
|
|
|
formats: ['es', 'cjs'],
|
2024-09-25 15:17:58 +00:00
|
|
|
fileName: format => {
|
|
|
|
return `[name].${format}.js`
|
|
|
|
},
|
2023-03-13 21:52:43 +00:00
|
|
|
},
|
|
|
|
sourcemap: true,
|
|
|
|
emptyOutDir: mode === 'production',
|
|
|
|
rollupOptions: {
|
|
|
|
external,
|
2024-09-25 15:17:58 +00:00
|
|
|
// makes 'use client' directive work
|
|
|
|
output: {
|
|
|
|
preserveModules: true,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
preserveDirectives({ suppressPreserveModulesWarning: true }) as any,
|
|
|
|
],
|
2023-03-13 21:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2024-09-25 15:17:58 +00:00
|
|
|
plugins: [react()],
|
2023-03-13 21:52:43 +00:00
|
|
|
|
|
|
|
test: {
|
|
|
|
environment: 'happy-dom',
|
|
|
|
},
|
|
|
|
}
|
2023-01-10 11:24:24 +00:00
|
|
|
})
|