diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b604a7d..e0a47703 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,13 +37,13 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node_version: [18, 20] + node_version: [20, 22, 24] include: # Active LTS + other OS - os: macos-latest - node_version: 20 + node_version: 22 - os: windows-latest - node_version: 20 + node_version: 22 fail-fast: false name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}" diff --git a/eslint.config.js b/eslint.config.js index c0c7d262..688137a1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -120,13 +120,13 @@ export default tseslint.config( 'n/no-unsupported-features/es-builtins': [ 'error', { - version: '^18.0.0 || >=20.0.0', + version: '^20.19.0 || >=22.12.0', }, ], 'n/no-unsupported-features/node-builtins': [ 'error', { - version: '^18.0.0 || >=20.0.0', + version: '^20.19.0 || >=22.12.0', }, ], '@typescript-eslint/explicit-module-boundary-types': 'off', @@ -150,7 +150,7 @@ export default tseslint.config( 'n/no-unsupported-features/node-builtins': [ 'error', { - version: '^18.0.0 || >=20.0.0', + version: '^20.19.0 || >=22.12.0', allowExperimental: true, }, ], diff --git a/package.json b/package.json index 14afee37..c9324ba8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "type": "module", "engines": { - "node": "^18.0.0 || >=20.0.0" + "node": "^20.19.0 || >=22.12.0" }, "homepage": "https://github.com/vitejs/vite-plugin-vue/", "repository": { diff --git a/packages/plugin-vue-jsx/build.config.ts b/packages/plugin-vue-jsx/build.config.ts index 360c2e7c..a74f5d85 100644 --- a/packages/plugin-vue-jsx/build.config.ts +++ b/packages/plugin-vue-jsx/build.config.ts @@ -4,7 +4,4 @@ export default defineBuildConfig({ entries: ['src/index'], clean: true, declaration: true, - rollup: { - emitCJS: true, - }, }) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index cbb74198..7576c701 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,29 +1,23 @@ { "name": "@vitejs/plugin-vue-jsx", "version": "4.2.0", - "type": "commonjs", + "type": "module", "license": "MIT", "author": "Evan You", "files": [ "dist" ], - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", "exports": { - ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } + ".": "./dist/index.mjs", + "./package.json": "./package.json" }, "scripts": { "dev": "unbuild --stub", - "build": "unbuild && pnpm run patch-cjs", - "patch-cjs": "tsx ../../scripts/patchCJS.ts", + "build": "unbuild", "prepublishOnly": "npm run build" }, "engines": { - "node": "^18.0.0 || >=20.0.0" + "node": "^20.19.0 || >=22.12.0" }, "repository": { "type": "git", @@ -44,7 +38,7 @@ "vite": "catalog:" }, "peerDependencies": { - "vite": "^5.0.0 || ^6.0.0", + "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0", "vue": "^3.0.0" } } diff --git a/packages/plugin-vue-jsx/src/index.ts b/packages/plugin-vue-jsx/src/index.ts index bdec6c58..2bfb06fb 100644 --- a/packages/plugin-vue-jsx/src/index.ts +++ b/packages/plugin-vue-jsx/src/index.ts @@ -12,7 +12,7 @@ import { } from '@rolldown/pluginutils' import type { Options } from './types' -export * from './types' +export type * from './types' const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper' const ssrRegisterHelperCode = @@ -328,17 +328,17 @@ function isDefineComponentCall( ) } -const hash = - // eslint-disable-next-line n/no-unsupported-features/node-builtins -- crypto.hash is supported in Node 21.7.0+, 20.12.0+ - crypto.hash ?? - (( - algorithm: string, - data: crypto.BinaryLike, - outputEncoding: crypto.BinaryToTextEncoding, - ) => crypto.createHash(algorithm).update(data).digest(outputEncoding)) - function getHash(text: string) { - return hash('sha256', text, 'hex').substring(0, 8) + return crypto.hash('sha256', text, 'hex').substring(0, 8) } export default vueJsxPlugin + +// Compat for require +function vueJsxPluginCjs(this: unknown, options: Options): Plugin { + return vueJsxPlugin.call(this, options) +} +Object.assign(vueJsxPluginCjs, { + default: vueJsxPluginCjs, +}) +export { vueJsxPluginCjs as 'module.exports' } diff --git a/packages/plugin-vue-jsx/tsconfig.json b/packages/plugin-vue-jsx/tsconfig.json index 3a3117f2..4f4926b9 100644 --- a/packages/plugin-vue-jsx/tsconfig.json +++ b/packages/plugin-vue-jsx/tsconfig.json @@ -3,9 +3,9 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "Node", + "target": "es2023", + "module": "preserve", + "moduleResolution": "bundler", "strict": true, "declaration": true, "sourceMap": true, diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index 3fe3cd3f..54ea8a58 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,11 @@ +## 6.0.0-beta.2 (2025-06-06) + +* refactor!: bump required node version to 20.19+, 22.12+ and drop CJS build (#596) ([56df545](https://github.com/vitejs/vite-plugin-vue/commit/56df545)), closes [#596](https://github.com/vitejs/vite-plugin-vue/issues/596) +* feat: add Vite 7 support (#597) ([12f2881](https://github.com/vitejs/vite-plugin-vue/commit/12f2881)), closes [#597](https://github.com/vitejs/vite-plugin-vue/issues/597) +* fix: template src sourcemap source (#267) ([de18693](https://github.com/vitejs/vite-plugin-vue/commit/de18693)), closes [#267](https://github.com/vitejs/vite-plugin-vue/issues/267) + + + ## 6.0.0-beta.1 (2025-06-02) * fix(vue): import with query (#592) ([b0400f3](https://github.com/vitejs/vite-plugin-vue/commit/b0400f3)), closes [#592](https://github.com/vitejs/vite-plugin-vue/issues/592) diff --git a/packages/plugin-vue/build.config.ts b/packages/plugin-vue/build.config.ts index 33fef7f6..12d46d0e 100644 --- a/packages/plugin-vue/build.config.ts +++ b/packages/plugin-vue/build.config.ts @@ -6,7 +6,6 @@ export default defineBuildConfig({ clean: true, declaration: 'compatible', rollup: { - emitCJS: true, inlineDependencies: true, }, }) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index 34bec69a..8e643a9c 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,29 +1,23 @@ { "name": "@vitejs/plugin-vue", - "version": "6.0.0-beta.1", - "type": "commonjs", + "version": "6.0.0-beta.2", + "type": "module", "license": "MIT", "author": "Evan You", "files": [ "dist" ], - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", "exports": { - ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } + ".": "./dist/index.mjs", + "./package.json": "./package.json" }, "scripts": { "dev": "unbuild --stub", - "build": "unbuild && pnpm run patch-cjs", - "patch-cjs": "tsx ../../scripts/patchCJS.ts", + "build": "unbuild", "prepublishOnly": "npm run build" }, "engines": { - "node": "^18.0.0 || >=20.0.0" + "node": "^20.19.0 || >=22.12.0" }, "repository": { "type": "git", @@ -35,7 +29,7 @@ }, "homepage": "https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue#readme", "peerDependencies": { - "vite": "^5.0.0 || ^6.0.0", + "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0", "vue": "^3.2.25" }, "devDependencies": { diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index e4e0b4ee..c1af1840 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -490,6 +490,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { if (query.type === 'template') { return transformTemplateAsModule( code, + filename, descriptor, options.value, this, @@ -516,3 +517,13 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { function ensureArray(value: T | T[]): T[] { return Array.isArray(value) ? value : [value] } + +// Compat for require +function vuePluginCjs(this: unknown, options: Options): Plugin { + return vuePlugin.call(this, options) +} +Object.assign(vuePluginCjs, { + default: vuePluginCjs, + parseVueRequest, +}) +export { vuePluginCjs as 'module.exports' } diff --git a/packages/plugin-vue/src/script.ts b/packages/plugin-vue/src/script.ts index 899612d9..2f63f770 100644 --- a/packages/plugin-vue/src/script.ts +++ b/packages/plugin-vue/src/script.ts @@ -74,7 +74,12 @@ export function resolveScript( id: descriptor.id, isProd: options.isProduction, inlineTemplate: isUseInlineTemplate(descriptor, options), - templateOptions: resolveTemplateCompilerOptions(descriptor, options, ssr), + templateOptions: resolveTemplateCompilerOptions( + descriptor, + options, + descriptor.filename, + ssr, + ), sourceMap: options.sourceMap, genDefaultAs: canInlineMain(descriptor, options) ? scriptIdentifier diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index 8d8f3ba1..f9e2eddf 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -13,6 +13,7 @@ import type { ResolvedOptions } from './index' export async function transformTemplateAsModule( code: string, + filename: string, descriptor: SFCDescriptor, options: ResolvedOptions, pluginContext: Rollup.TransformPluginContext, @@ -24,6 +25,7 @@ export async function transformTemplateAsModule( }> { const result = compile( code, + filename, descriptor, options, pluginContext, @@ -62,6 +64,7 @@ export function transformTemplateInMain( ): SFCTemplateCompileResults { const result = compile( code, + descriptor.filename, descriptor, options, pluginContext, @@ -80,16 +83,16 @@ export function transformTemplateInMain( // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function compile( code: string, + filename: string, descriptor: SFCDescriptor, options: ResolvedOptions, pluginContext: Rollup.PluginContext, ssr: boolean, customElement: boolean, ) { - const filename = descriptor.filename resolveScript(descriptor, options, ssr, customElement) const result = options.compiler.compileTemplate({ - ...resolveTemplateCompilerOptions(descriptor, options, ssr)!, + ...resolveTemplateCompilerOptions(descriptor, options, filename, ssr)!, source: code, }) @@ -118,6 +121,7 @@ export function compile( export function resolveTemplateCompilerOptions( descriptor: SFCDescriptor, options: ResolvedOptions, + filename: string, ssr: boolean, ): Omit | undefined { const block = descriptor.template @@ -126,7 +130,7 @@ export function resolveTemplateCompilerOptions( } const resolvedScript = getResolvedScript(descriptor, ssr) const hasScoped = descriptor.styles.some((s) => s.scoped) - const { id, filename, cssVars } = descriptor + const { id, cssVars } = descriptor let transformAssetUrls = options.template?.transformAssetUrls // compiler-sfc should export `AssetURLOptions` diff --git a/packages/plugin-vue/tsconfig.json b/packages/plugin-vue/tsconfig.json index cec54d61..c22bb7b8 100644 --- a/packages/plugin-vue/tsconfig.json +++ b/packages/plugin-vue/tsconfig.json @@ -3,9 +3,9 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "node", + "target": "es2023", + "module": "preserve", + "moduleResolution": "bundler", "strict": true, "declaration": true, "sourceMap": true, diff --git a/playground/tsconfig.json b/playground/tsconfig.json index 54fb5cd9..7f7356c8 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -2,7 +2,7 @@ "include": ["."], "exclude": ["**/dist/**"], "compilerOptions": { - "target": "ES2020", + "target": "ES2023", "module": "ESNext", "outDir": "dist", "baseUrl": ".", diff --git a/playground/vue-sourcemap/Main.vue b/playground/vue-sourcemap/Main.vue index 8b092e88..d63d3799 100644 --- a/playground/vue-sourcemap/Main.vue +++ b/playground/vue-sourcemap/Main.vue @@ -7,6 +7,7 @@ +