Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve build #1432

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions packages/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import dts from 'vite-plugin-dts'
import pkg from './package.json'

const projectRootDir = resolve(__dirname)

// A bit of a hack, but lets us use the proper extension in chunk filenames
let currentFormat = ''

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
Expand All @@ -28,11 +32,13 @@ export default defineConfig({
],
},
build: {
minify: true,
minify: false,
target: 'esnext',
sourcemap: true,
lib: {
name: 'reka-ui',
fileName: (format, name) => {
currentFormat = format
return `${name}.${format === 'es' ? 'js' : 'cjs'}`
},
entry: {
Expand All @@ -42,12 +48,27 @@ export default defineConfig({
},
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library (Vue)
external: ['vue', '@floating-ui/vue', '@internationalized/date', '@internationalized/number'],
external: [
'nanoid/non-secure',
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
],
output: {
preserveModules: true,
// Don't rely on preserveModules
// It creates a lot of unwanted files because of the multiple sections of SFC files
manualChunks: (moduleId, meta) => {
const info = meta.getModuleInfo(moduleId)
if (!info.isIncluded) {
// Don't create empty chunks
return null
}

const [namespace, file] = moduleId.split('?')[0].split('/').slice(-2)
return `${namespace}/${file.slice(0, file.lastIndexOf('.'))}`
},

exports: 'named',
chunkFileNames: chunk => `${chunk.name}.${currentFormat === 'es' ? 'js' : 'cjs'}`,
assetFileNames: (chunkInfo) => {
if (chunkInfo.name === 'style.css')
return 'index.css'
Expand Down