Skip to content

Commit dee6067

Browse files
authored
feat!: rollup v4 (#14508)
1 parent a76be5d commit dee6067

File tree

42 files changed

+294
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+294
-261
lines changed

docs/guide/migration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
Vite no longer supports Node.js 14 / 16 / 17 / 19, which reached its EOL. Node.js 18 / 20+ is now required.
66

7+
## Rollup 4
8+
9+
Vite is now using Rollup 4 which also brings along its breaking changes, in particular:
10+
11+
- Import assertions (`assertions` prop) has been renamed to import attributes (`attributes` prop).
12+
- Acorn plugins are no longer supported.
13+
- For Vite plugins, `this.resolve` `skipSelf` option is now `true` by default.
14+
- For Vite plugins, `this.parse` now only supports the `allowReturnOutsideFunction` option for now.
15+
16+
Read the full breaking changes in [Rollup's release notes](https://github.com/rollup/rollup/releases/tag/v4.0.0) for build-related changes in `build.rollupOptions`.
17+
718
## Deprecate CJS Node API
819

920
The CJS Node API of Vite is deprecated. When calling `require('vite')`, a deprecation warning is now logged. You should update your files or frameworks to import the ESM build of Vite instead.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"playwright-chromium": "^1.39.0",
7777
"prettier": "3.0.3",
7878
"rimraf": "^5.0.5",
79-
"rollup": "^3.29.2",
79+
"rollup": "^4.1.4",
8080
"simple-git-hooks": "^2.9.0",
8181
"tslib": "^2.6.2",
8282
"tsx": "^3.13.0",

packages/create-vite/build.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineBuildConfig({
2323
'rollup:options'(ctx, options) {
2424
options.plugins = [
2525
options.plugins,
26+
// @ts-expect-error TODO: unbuild uses rollup v3 and Vite uses rollup v4
2627
licensePlugin(
2728
path.resolve(__dirname, './LICENSE'),
2829
'create-vite license',

packages/vite/LICENSE.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,6 @@ Repository: https://github.com/acornjs/acorn.git
566566
567567
---------------------------------------
568568

569-
## acorn-import-assertions
570-
License: MIT
571-
By: Sven Sauleau
572-
Repository: https://github.com/xtuc/acorn-import-assertions
573-
574-
---------------------------------------
575-
576569
## acorn-walk
577570
License: MIT
578571
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine

packages/vite/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"dependencies": {
7777
"esbuild": "^0.19.3",
7878
"postcss": "^8.4.31",
79-
"rollup": "^3.29.4"
79+
"rollup": "^4.1.4"
8080
},
8181
"optionalDependencies": {
8282
"fsevents": "~2.3.3"
@@ -94,7 +94,6 @@
9494
"@types/escape-html": "^1.0.2",
9595
"@types/pnpapi": "^0.0.3",
9696
"acorn": "^8.10.0",
97-
"acorn-import-assertions": "^1.9.0",
9897
"acorn-walk": "^8.2.0",
9998
"cac": "^6.7.14",
10099
"chokidar": "^3.5.3",

packages/vite/rollup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function createNodeConfig(isProduction: boolean) {
161161
external: [
162162
'fsevents',
163163
'lightningcss',
164+
'rollup/parseAst',
164165
...Object.keys(pkg.dependencies),
165166
...(isProduction ? [] : Object.keys(pkg.devDependencies)),
166167
],

packages/vite/src/node/build.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {
1414
RollupLog,
1515
RollupOptions,
1616
RollupOutput,
17-
RollupWarning,
1817
RollupWatcher,
1918
WatcherOptions,
2019
} from 'rollup'
@@ -45,7 +44,6 @@ import { initDepsOptimizer } from './optimizer'
4544
import { loadFallbackPlugin } from './plugins/loadFallback'
4645
import { findNearestPackageData } from './packages'
4746
import type { PackageCache } from './packages'
48-
import { ensureWatchPlugin } from './plugins/ensureWatch'
4947
import { ESBUILD_MODULES_TARGET, VERSION } from './constants'
5048
import { resolveChokidarOptions } from './watch'
5149
import { completeSystemWrapPlugin } from './plugins/completeSystemWrap'
@@ -426,7 +424,6 @@ export async function resolveBuildPlugins(config: ResolvedConfig): Promise<{
426424
return {
427425
pre: [
428426
completeSystemWrapPlugin(),
429-
...(options.watch ? [ensureWatchPlugin()] : []),
430427
...(usePluginCommonjs ? [commonjsPlugin(options.commonjsOptions)] : []),
431428
dataURIPlugin(),
432429
...((
@@ -858,7 +855,7 @@ const dynamicImportWarningIgnoreList = [
858855
]
859856

860857
export function onRollupWarning(
861-
warning: RollupWarning,
858+
warning: RollupLog,
862859
warn: LoggingFunction,
863860
config: ResolvedConfig,
864861
): void {

packages/vite/src/node/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
150150
source: string,
151151
importer: string | undefined,
152152
options: {
153-
assertions: Record<string, string>
153+
attributes: Record<string, string>
154154
custom?: CustomPluginOptions
155155
ssr?: boolean
156156
/**

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
} from '../utils'
2828
import { FS_PREFIX } from '../constants'
2929

30-
export const assetUrlRE = /__VITE_ASSET__([a-z\d]+)__(?:\$_(.*?)__)?/g
30+
// referenceId is base64url but replaces - with $
31+
export const assetUrlRE = /__VITE_ASSET__([\w$]+)__(?:\$_(.*?)__)?/g
3132

3233
const rawRE = /(?:\?|&)raw(?:&|$)/
3334
export const urlRE = /(\?|&)url(?:&|$)/
@@ -78,10 +79,10 @@ export function renderAssetUrlInJS(
7879
let s: MagicString | undefined
7980

8081
// Urls added with JS using e.g.
81-
// imgElement.src = "__VITE_ASSET__5aa0ddc0__" are using quotes
82+
// imgElement.src = "__VITE_ASSET__5aA0Ddc0__" are using quotes
8283

8384
// Urls added in CSS that is imported in JS end up like
84-
// var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aa0ddc0__)}\n";
85+
// var inlined = ".inlined{color:green;background:url(__VITE_ASSET__5aA0Ddc0__)}\n";
8586

8687
// In both cases, the wrapping should already be fine
8788

@@ -107,7 +108,7 @@ export function renderAssetUrlInJS(
107108
s.update(match.index, match.index + full.length, replacementString)
108109
}
109110

110-
// Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths
111+
// Replace __VITE_PUBLIC_ASSET__5aA0Ddc0__ with absolute paths
111112

112113
const publicAssetUrlMap = publicAssetUrlCache.get(config)!
113114
publicAssetUrlRE.lastIndex = 0
@@ -179,6 +180,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
179180
// raw requests, read from disk
180181
if (rawRE.test(id)) {
181182
const file = checkPublicFile(id, config) || cleanUrl(id)
183+
this.addWatchFile(file)
182184
// raw query, read file and return as string
183185
return `export default ${JSON.stringify(
184186
await fsp.readFile(file, 'utf-8'),

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)