diff --git a/.changeset/true-ghosts-shop.md b/.changeset/true-ghosts-shop.md
new file mode 100644
index 00000000..e61f4c40
--- /dev/null
+++ b/.changeset/true-ghosts-shop.md
@@ -0,0 +1,5 @@
+---
+"@devup-ui/vite-plugin": patch
+---
+
+Add optimize for lib
diff --git a/apps/vite-lib/package.json b/apps/vite-lib/package.json
index 711d0dbd..122bbc52 100644
--- a/apps/vite-lib/package.json
+++ b/apps/vite-lib/package.json
@@ -3,6 +3,10 @@
"version": "0.1.0",
"type": "module",
"private": true,
+ "exports": {
+ "import": "./dist/index.js",
+ "require": "./dist/index.cjs"
+ },
"scripts": {
"build": "vite build",
"lint": "tsc && eslint"
diff --git a/apps/vite/package.json b/apps/vite/package.json
index fe3a4e75..8d4b8f1b 100644
--- a/apps/vite/package.json
+++ b/apps/vite/package.json
@@ -12,7 +12,8 @@
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0",
- "@devup-ui/react": "workspace:*"
+ "@devup-ui/react": "workspace:*",
+ "vite-lib-example": "workspace:*"
},
"devDependencies": {
"@devup-ui/vite-plugin": "workspace:*",
diff --git a/apps/vite/src/App.tsx b/apps/vite/src/App.tsx
index c7b01e9d..a980c083 100644
--- a/apps/vite/src/App.tsx
+++ b/apps/vite/src/App.tsx
@@ -1,4 +1,5 @@
import { Box, Text } from '@devup-ui/react'
+import { Lib } from 'vite-lib-example'
export default function App() {
return (
@@ -11,6 +12,7 @@ export default function App() {
color="red"
>
hello
+
typo
diff --git a/apps/vite/vite.config.ts b/apps/vite/vite.config.ts
index a2fa73c8..b41e40a9 100644
--- a/apps/vite/vite.config.ts
+++ b/apps/vite/vite.config.ts
@@ -4,5 +4,10 @@ import { defineConfig } from 'vite'
// https://vite.dev/config/
export default defineConfig({
- plugins: [react(), DevupUI()],
+ plugins: [
+ react(),
+ DevupUI({
+ include: ['vite-lib-example'],
+ }),
+ ],
})
diff --git a/packages/vite-plugin/src/__tests__/plugin.test.ts b/packages/vite-plugin/src/__tests__/plugin.test.ts
index 350d83e9..2a9a3e85 100644
--- a/packages/vite-plugin/src/__tests__/plugin.test.ts
+++ b/packages/vite-plugin/src/__tests__/plugin.test.ts
@@ -68,6 +68,9 @@ describe('devupUIPlugin', () => {
ignored: [`!${devupPath}`],
},
},
+ optimizeDeps: {
+ exclude: [],
+ },
build: {
rollupOptions: {
output: {
@@ -331,7 +334,7 @@ describe('devupUIPlugin', () => {
'C:/devfive/minions-front/apps/vendor/node_modules/.vite/deps/@devup_product-system.js?v=63f19272',
)
expect(codeExtract).toHaveBeenCalledWith(
- 'C:/devfive/minions-front/apps/vendor/node_modules/.vite/deps/@devup_product-system.js?v=63f19272',
+ 'C:/devfive/minions-front/apps/vendor/node_modules/.vite/deps/@devup_product-system.js',
'code',
libPackage,
cssFile,
diff --git a/packages/vite-plugin/src/plugin.ts b/packages/vite-plugin/src/plugin.ts
index cab279b2..11642dc1 100644
--- a/packages/vite-plugin/src/plugin.ts
+++ b/packages/vite-plugin/src/plugin.ts
@@ -83,6 +83,9 @@ export function DevupUI({
'process.env.DEVUP_UI_DEFAULT_THEME':
JSON.stringify(getDefaultTheme()),
},
+ optimizeDeps: {
+ exclude: include,
+ },
}
if (extractCss) {
ret['build'] = {
@@ -131,18 +134,27 @@ export function DevupUI({
async transform(code, id) {
if (!extractCss) return
+ const fileName = id.split('?')[0]
if (
include.length
? new RegExp(
- `node_modules(?!(.*${include.join('|').replaceAll('/', '[\\/\\\\_]')})([\\/\\\\.]|$))`,
- ).test(id)
+ `node_modules(?!(${include
+ .map((i) => `.*${i}`)
+ .join('|')
+ .replaceAll('/', '[\\/\\\\_]')})([\\/\\\\.]|$))`,
+ ).test(fileName)
: id.includes('node_modules')
) {
return
}
- if (!/\.(tsx|ts|js|mjs|jsx)$/i.test(id.split('?')[0])) return
+ if (!/\.(tsx|ts|js|mjs|jsx)$/i.test(fileName)) return
- const { code: retCode, css } = codeExtract(id, code, libPackage, cssFile)
+ const { code: retCode, css } = codeExtract(
+ fileName,
+ code,
+ libPackage,
+ cssFile,
+ )
if (css && globalCss.length < css.length) {
globalCss = css
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 503d2a68..e9a24714 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -142,6 +142,9 @@ importers:
react-dom:
specifier: ^19.0.0
version: 19.0.0(react@19.0.0)
+ vite-lib-example:
+ specifier: workspace:*
+ version: link:../vite-lib
devDependencies:
'@devup-ui/vite-plugin':
specifier: workspace:*
@@ -936,6 +939,10 @@ packages:
resolution: {integrity: sha512-AOPI3D+a8dXnja+iwsUqGRjr1BbZIe771sXdapOtYI531gSqpi92vXivKcq2asu/DFpdl1ceFAKZyRzK2PCVcQ==}
engines: {node: '>=6.9.0'}
+ '@babel/runtime@7.27.0':
+ resolution: {integrity: sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw==}
+ engines: {node: '>=6.9.0'}
+
'@babel/template@7.25.9':
resolution: {integrity: sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==}
engines: {node: '>=6.9.0'}
@@ -5541,6 +5548,10 @@ snapshots:
dependencies:
regenerator-runtime: 0.14.1
+ '@babel/runtime@7.27.0':
+ dependencies:
+ regenerator-runtime: 0.14.1
+
'@babel/template@7.25.9':
dependencies:
'@babel/code-frame': 7.26.2
@@ -6523,7 +6534,7 @@ snapshots:
'@testing-library/dom@10.4.0':
dependencies:
'@babel/code-frame': 7.26.2
- '@babel/runtime': 7.26.7
+ '@babel/runtime': 7.27.0
'@types/aria-query': 5.0.4
aria-query: 5.3.0
chalk: 4.1.2