Skip to content

Commit 8ecd7ba

Browse files
committed
feat: expose CustomPluginOptionsVite type
1 parent f612e0f commit 8ecd7ba

File tree

7 files changed

+193
-234
lines changed

7 files changed

+193
-234
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"playwright-chromium": "^1.50.1",
6969
"premove": "^4.0.0",
7070
"prettier": "3.5.3",
71-
"rollup": "^4.30.1",
71+
"rollup": "^4.34.9",
7272
"rollup-plugin-esbuild": "^6.2.1",
7373
"simple-git-hooks": "^2.11.1",
7474
"tslib": "^2.8.1",

packages/vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"dependencies": {
8888
"esbuild": "^0.25.0",
8989
"postcss": "^8.5.3",
90-
"rollup": "^4.30.1"
90+
"rollup": "^4.34.9"
9191
},
9292
"optionalDependencies": {
9393
"fsevents": "~2.3.3"

packages/vite/src/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export type {
205205
GeneralImportGlobOptions,
206206
KnownAsTypeMap,
207207
} from 'types/importGlob'
208-
export type { ChunkMetadata } from 'types/metadata'
208+
export type { ChunkMetadata, CustomPluginOptionsVite } from 'types/metadata'
209209

210210
// dep types
211211
export type {

packages/vite/src/node/plugin.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,24 +323,6 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
323323
>
324324
}
325325

326-
export interface CustomPluginOptionsVite {
327-
/**
328-
* If this is a CSS Rollup module, you can scope to its importer's exports
329-
* so that if those exports are treeshaken away, the CSS module will also
330-
* be treeshaken.
331-
*
332-
* The "importerId" must import the CSS Rollup module statically.
333-
*
334-
* Example config if the CSS id is `/src/App.vue?vue&type=style&lang.css`:
335-
* ```js
336-
* cssScopeTo: ['/src/App.vue', 'default']
337-
* ```
338-
*
339-
* @experimental
340-
*/
341-
cssScopeTo?: [importerId: string, exportName: string | undefined]
342-
}
343-
344326
export type HookHandler<T> = T extends ObjectHook<infer H> ? H : T
345327

346328
export type PluginWithRequiredHook<K extends keyof Plugin> = Plugin & {

packages/vite/src/node/plugins/css.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
TransformAttributeResult as LightningCssTransformAttributeResult,
3838
TransformResult as LightningCssTransformResult,
3939
} from 'lightningcss'
40+
import type { CustomPluginOptionsVite } from 'types/metadata'
4041
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
4142
import type { EnvironmentModuleNode } from '../server/moduleGraph'
4243
import {
@@ -54,7 +55,7 @@ import {
5455
SPECIAL_QUERY_RE,
5556
} from '../constants'
5657
import type { ResolvedConfig } from '../config'
57-
import type { CustomPluginOptionsVite, Plugin } from '../plugin'
58+
import type { Plugin } from '../plugin'
5859
import { checkPublicFile } from '../publicDir'
5960
import {
6061
arraify,
@@ -650,11 +651,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
650651
// NOTE: `this.getModuleInfo` can be undefined when the plugin is called directly
651652
// adding `?.` temporary to avoid unocss from breaking
652653
// TODO: remove `?.` after `this.getModuleInfo` in Vite 7
653-
(
654-
this.getModuleInfo?.(id)?.meta?.vite as
655-
| CustomPluginOptionsVite
656-
| undefined
657-
)?.cssScopeTo
654+
this.getModuleInfo?.(id)?.meta?.vite?.cssScopeTo
658655

659656
// record css
660657
if (!inlined) {

packages/vite/types/metadata.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ export interface ChunkMetadata {
33
importedCss: Set<string>
44
}
55

6+
export interface CustomPluginOptionsVite {
7+
/**
8+
* If this is a CSS Rollup module, you can scope to its importer's exports
9+
* so that if those exports are treeshaken away, the CSS module will also
10+
* be treeshaken.
11+
*
12+
* The "importerId" must import the CSS Rollup module statically.
13+
*
14+
* Example config if the CSS id is `/src/App.vue?vue&type=style&lang.css`:
15+
* ```js
16+
* cssScopeTo: ['/src/App.vue', 'default']
17+
* ```
18+
*
19+
* @experimental
20+
*/
21+
cssScopeTo?: [importerId: string, exportName: string | undefined]
22+
}
23+
624
declare module 'rollup' {
725
export interface RenderedChunk {
826
viteMetadata?: ChunkMetadata
927
}
28+
29+
export interface CustomPluginOptions {
30+
vite?: CustomPluginOptionsVite
31+
}
1032
}

0 commit comments

Comments
 (0)