Skip to content

Commit 15abc01

Browse files
authored
feat(types): expose CustomPluginOptionsVite type (#19557)
1 parent 8c04c69 commit 15abc01

File tree

7 files changed

+196
-175
lines changed

7 files changed

+196
-175
lines changed

package.json

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"esbuild": "^0.25.0",
8989
"picomatch": "^4.0.2",
9090
"postcss": "^8.5.3",
91-
"rollup": "^4.30.1",
91+
"rollup": "^4.34.9",
9292
"tinyglobby": "^0.2.12"
9393
},
9494
"optionalDependencies": {

packages/vite/src/node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export type {
211211
GeneralImportGlobOptions,
212212
KnownAsTypeMap,
213213
} from 'types/importGlob'
214-
export type { ChunkMetadata } from 'types/metadata'
214+
export type { ChunkMetadata, CustomPluginOptionsVite } from 'types/metadata'
215215

216216
// dep types
217217
export type {

packages/vite/src/node/plugin.ts

-18
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,6 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
327327
>
328328
}
329329

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

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

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type {
3838
TransformAttributeResult as LightningCssTransformAttributeResult,
3939
TransformResult as LightningCssTransformResult,
4040
} from 'lightningcss'
41+
import type { CustomPluginOptionsVite } from 'types/metadata'
4142
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
4243
import type { EnvironmentModuleNode } from '../server/moduleGraph'
4344
import {
@@ -55,7 +56,7 @@ import {
5556
SPECIAL_QUERY_RE,
5657
} from '../constants'
5758
import type { ResolvedConfig } from '../config'
58-
import type { CustomPluginOptionsVite, Plugin } from '../plugin'
59+
import type { Plugin } from '../plugin'
5960
import { checkPublicFile } from '../publicDir'
6061
import {
6162
arraify,
@@ -656,11 +657,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
656657

657658
// If this CSS is scoped to its importers exports, check if those importers exports
658659
// are rendered in the chunks. If they are not, we can skip bundling this CSS.
659-
const cssScopeTo = (
660-
this.getModuleInfo(id)?.meta?.vite as
661-
| CustomPluginOptionsVite
662-
| undefined
663-
)?.cssScopeTo
660+
const cssScopeTo = this.getModuleInfo(id)?.meta?.vite?.cssScopeTo
664661
if (
665662
cssScopeTo &&
666663
!isCssScopeToRendered(cssScopeTo, renderedModules)

packages/vite/types/metadata.d.ts

+22
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)