Skip to content

Commit 04d0391

Browse files
committed
Add include
1 parent 5a2ab9d commit 04d0391

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

.changeset/short-files-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/vite-plugin": patch
3+
---
4+
5+
Add include

packages/react/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ You can use responsive and pseudo selector.
143143
// Responsive with Selector
144144
<Box _hover={{bg: ["red", "blue"]}}/>
145145

146-
// Same
146+
// Another way
147147
<Box _hover={[{bg: "red"}, {bg: "blue"}]}/>
148148

149149
```
6.66 KB
Binary file not shown.

packages/vite-plugin/src/__tests__/plugin.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,46 @@ describe('devupUIPlugin', () => {
298298
expect((plugin as any).apply({}, { command: 'build' })).toBe(true)
299299
})
300300

301+
it('should include', () => {
302+
const devupPath = 'devup.json'
303+
const interfacePath = '.df'
304+
const cssFile = join(_dirname, 'devup-ui.css')
305+
const libPackage = '@devup-ui/react'
306+
const plugin = DevupUI({
307+
package: libPackage,
308+
cssFile,
309+
devupPath,
310+
interfacePath,
311+
include: ['@devup/product-system'],
312+
})
313+
vi.mocked(codeExtract).mockReturnValue({
314+
css: 'css code',
315+
code: 'code',
316+
} as any)
317+
;(plugin as any).transform('code', 'node_modules/@devup/test/dist/index.js')
318+
expect(codeExtract).toBeCalledTimes(0)
319+
;(plugin as any).transform(
320+
'code',
321+
'node_modules/@devup/product-system/dist/index.js',
322+
)
323+
expect(codeExtract).toHaveBeenCalledWith(
324+
'node_modules/@devup/product-system/dist/index.js',
325+
'code',
326+
libPackage,
327+
cssFile,
328+
)
329+
;(plugin as any).transform(
330+
'code',
331+
'C:/devfive/minions-front/apps/vendor/node_modules/.vite/deps/@devup_product-system.js?v=63f19272',
332+
)
333+
expect(codeExtract).toHaveBeenCalledWith(
334+
'C:/devfive/minions-front/apps/vendor/node_modules/.vite/deps/@devup_product-system.js?v=63f19272',
335+
'code',
336+
libPackage,
337+
cssFile,
338+
)
339+
})
340+
301341
describe('basic', () => {
302342
const devupPath = 'devup.json'
303343
const interfacePath = '.df'

packages/vite-plugin/src/plugin.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export interface DevupUIPluginOptions {
1919
interfacePath: string
2020
extractCss: boolean
2121
debug: boolean
22+
include: string[]
2223
}
2324

2425
function writeDataFiles(
25-
options: Omit<DevupUIPluginOptions, 'extractCss' | 'debug'>,
26+
options: Omit<DevupUIPluginOptions, 'extractCss' | 'debug' | 'include'>,
2627
) {
2728
if (!existsSync(options.interfacePath)) mkdirSync(options.interfacePath)
2829
if (existsSync(options.devupPath)) {
@@ -56,6 +57,7 @@ export function DevupUI({
5657
cssFile = resolve(interfacePath, 'devup-ui.css'),
5758
extractCss = true,
5859
debug = false,
60+
include = [],
5961
}: Partial<DevupUIPluginOptions> = {}): PluginOption {
6062
setDebug(debug)
6163
try {
@@ -128,8 +130,17 @@ export function DevupUI({
128130
enforce: 'pre',
129131
async transform(code, id) {
130132
if (!extractCss) return
131-
if (id.includes('node_modules')) return
132-
if (!/\.(tsx|ts|js|mjs|jsx)$/i.test(id)) return
133+
134+
if (
135+
include.length
136+
? new RegExp(
137+
`node_modules(?!(.*${include.join('|').replaceAll('/', '[\\/\\\\_]')})([\\/\\\\.]|$))`,
138+
).test(id)
139+
: id.includes('node_modules')
140+
) {
141+
return
142+
}
143+
if (!/\.(tsx|ts|js|mjs|jsx)$/i.test(id.split('?')[0])) return
133144

134145
const { code: retCode, css } = codeExtract(id, code, libPackage, cssFile)
135146

0 commit comments

Comments
 (0)