Skip to content

Commit

Permalink
chore: improve build
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyynthia committed Nov 17, 2024
1 parent fc39270 commit 3d974f9
Showing 1 changed file with 26 additions and 5 deletions.
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

0 comments on commit 3d974f9

Please sign in to comment.