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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"playwright-chromium": "^1.50.1",
"premove": "^4.0.0",
"prettier": "3.5.3",
"rollup": "^4.30.1",
"rollup": "^4.34.9",
"rollup-plugin-esbuild": "^6.2.1",
"simple-git-hooks": "^2.11.1",
"tslib": "^2.8.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"esbuild": "^0.25.0",
"picomatch": "^4.0.2",
"postcss": "^8.5.3",
"rollup": "^4.30.1",
"rollup": "^4.34.9",
"tinyglobby": "^0.2.12"
},
"optionalDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export type {
GeneralImportGlobOptions,
KnownAsTypeMap,
} from 'types/importGlob'
export type { ChunkMetadata } from 'types/metadata'
export type { ChunkMetadata, CustomPluginOptionsVite } from 'types/metadata'

// dep types
export type {
Expand Down
18 changes: 0 additions & 18 deletions packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,24 +327,6 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
>
}

export interface CustomPluginOptionsVite {
/**
* If this is a CSS Rollup module, you can scope to its importer's exports
* so that if those exports are treeshaken away, the CSS module will also
* be treeshaken.
*
* The "importerId" must import the CSS Rollup module statically.
*
* Example config if the CSS id is `/src/App.vue?vue&type=style&lang.css`:
* ```js
* cssScopeTo: ['/src/App.vue', 'default']
* ```
*
* @experimental
*/
cssScopeTo?: [importerId: string, exportName: string | undefined]
}

export type HookHandler<T> = T extends ObjectHook<infer H> ? H : T

export type PluginWithRequiredHook<K extends keyof Plugin> = Plugin & {
Expand Down
9 changes: 3 additions & 6 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
TransformAttributeResult as LightningCssTransformAttributeResult,
TransformResult as LightningCssTransformResult,
} from 'lightningcss'
import type { CustomPluginOptionsVite } from 'types/metadata'
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
import type { EnvironmentModuleNode } from '../server/moduleGraph'
import {
Expand All @@ -55,7 +56,7 @@ import {
SPECIAL_QUERY_RE,
} from '../constants'
import type { ResolvedConfig } from '../config'
import type { CustomPluginOptionsVite, Plugin } from '../plugin'
import type { Plugin } from '../plugin'
import { checkPublicFile } from '../publicDir'
import {
arraify,
Expand Down Expand Up @@ -656,11 +657,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {

// If this CSS is scoped to its importers exports, check if those importers exports
// are rendered in the chunks. If they are not, we can skip bundling this CSS.
const cssScopeTo = (
this.getModuleInfo(id)?.meta?.vite as
| CustomPluginOptionsVite
| undefined
)?.cssScopeTo
const cssScopeTo = this.getModuleInfo(id)?.meta?.vite?.cssScopeTo
if (
cssScopeTo &&
!isCssScopeToRendered(cssScopeTo, renderedModules)
Expand Down
22 changes: 22 additions & 0 deletions packages/vite/types/metadata.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@ export interface ChunkMetadata {
importedCss: Set<string>
}

export interface CustomPluginOptionsVite {
/**
* If this is a CSS Rollup module, you can scope to its importer's exports
* so that if those exports are treeshaken away, the CSS module will also
* be treeshaken.
*
* The "importerId" must import the CSS Rollup module statically.
*
* Example config if the CSS id is `/src/App.vue?vue&type=style&lang.css`:
* ```js
* cssScopeTo: ['/src/App.vue', 'default']
* ```
*
* @experimental
*/
cssScopeTo?: [importerId: string, exportName: string | undefined]
}

declare module 'rollup' {
export interface RenderedChunk {
viteMetadata?: ChunkMetadata
}

export interface CustomPluginOptions {
vite?: CustomPluginOptionsVite
}
}
Loading