Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/brown-schools-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/vite-plugin": patch
---

Support storybook
9 changes: 3 additions & 6 deletions packages/vite-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { writeFile } from 'node:fs/promises'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

import { codeExtract, getThemeInterface } from '@devup-ui/wasm'
import { codeExtract, getCss, getThemeInterface } from '@devup-ui/wasm'
import { describe } from 'vitest'

import { DevupUI } from '../plugin'
Expand Down Expand Up @@ -344,13 +344,10 @@ describe('devupUIPlugin', () => {
Date.now = () => 1
expect((plugin as any).load('code')).toBeUndefined()
expect((plugin as any).load(cssFile)).toBeUndefined()
vi.mocked(getCss).mockReturnValueOnce('css code')
expect(
(plugin as any).load('devup-ui.css?v=some').length.toString(),
).toBe(
(plugin as any)
.resolveId(cssFile, 'code')
.substring(`devup-ui.css?v=${Date.now()}`.length),
)
).toBe('css code'.length.toString())
})
})
})
5 changes: 4 additions & 1 deletion packages/vite-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join, resolve } from 'node:path'

import {
codeExtract,
getCss,
getThemeInterface,
registerTheme,
setDebug,
Expand Down Expand Up @@ -115,7 +116,9 @@ export function DevupUI({
return `devup-ui.css?t=${Date.now().toString() + globalCss.length}`
},
load(id) {
if (id.split('?')[0] === 'devup-ui.css') return globalCss
if (id.split('?')[0] === 'devup-ui.css')
// for no share env like storybook
return (globalCss = getCss())
},
enforce: 'pre',
async transform(code, id) {
Expand Down