diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 8ab24f7b507c5c..fdec8e2ca4a2ae 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -208,9 +208,9 @@ describe('resolveBuildOutputs', () => { { format: 'es', }, - // { - // format: 'umd', - // }, + { + format: 'umd', + }, ]) }) @@ -249,7 +249,7 @@ describe('resolveBuildOutputs', () => { expect(resolveBuild).toThrowError(/Option "build\.lib\.name" is required/) }) - test.skip('throws an error when lib.name is missing on umd format', () => { + test('throws an error when lib.name is missing on umd format', () => { const logger = createLogger() const libOptions: LibraryOptions = { ...baseLibOptions, formats: ['umd'] } const resolveBuild = () => resolveBuildOutputs(void 0, libOptions, logger) @@ -268,7 +268,7 @@ describe('resolveBuildOutputs', () => { ) }) - test.skip('throws an error when output.name is missing on umd format', () => { + test('throws an error when output.name is missing on umd format', () => { const logger = createLogger() const libOptions: LibraryOptions = { ...baseLibOptions } const outputs: OutputOptions[] = [{ format: 'umd' }] @@ -372,7 +372,7 @@ describe('resolveLibFilename', () => { test('module package extensions', () => { const formatsToFilenames: FormatsToFileNames = [ ['es', 'my-lib.js'], - // ['umd', 'my-lib.umd.cjs'], + ['umd', 'my-lib.umd.cjs'], ['cjs', 'my-lib.cjs'], ['iife', 'my-lib.iife.js'], ] @@ -522,13 +522,13 @@ describe('resolveBuildOutputs', () => { expect(resolveBuildOutputs(undefined, libOptions, {} as Logger)).toEqual([ { format: 'es' }, - // { format: 'umd' }, + { format: 'umd' }, ]) expect( resolveBuildOutputs({ name: 'A' }, libOptions, {} as Logger), ).toEqual([ { format: 'es', name: 'A' }, - // { format: 'umd', name: 'A' }, + { format: 'umd', name: 'A' }, ]) expect( resolveBuildOutputs([{ name: 'A' }], libOptions, {} as Logger), @@ -555,7 +555,7 @@ describe('resolveBuildOutputs', () => { ).toEqual([{ name: 'A' }]) }) - test.skip('umd or iife: should not support multiple entries', () => { + test('umd or iife: should not support multiple entries', () => { ;['umd', 'iife'].forEach((format) => { expect(() => resolveBuildOutputs( @@ -572,7 +572,7 @@ describe('resolveBuildOutputs', () => { }) }) - test.skip('umd or iife: should define build.lib.name', () => { + test('umd or iife: should define build.lib.name', () => { ;['umd', 'iife'].forEach((format) => { expect(() => resolveBuildOutputs( diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 83ee7daa4e22f6..30b342ff14c9fe 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -313,7 +313,7 @@ export interface LibraryOptions { cssFileName?: string } -export type LibraryFormats = 'es' | 'cjs' | 'iife' // | 'umd' | 'system' +export type LibraryFormats = 'es' | 'cjs' | 'iife' | 'umd' // | 'system' export interface ModulePreloadOptions { /** @@ -759,7 +759,7 @@ async function buildEnvironment( ? `[name].[ext]` : path.posix.join(options.assetsDir, `[name]-[hash].[ext]`), inlineDynamicImports: - /* output.format === 'umd' || */ + output.format === 'umd' || output.format === 'iife' || (isSsrTargetWebworkerEnvironment && (typeof input === 'string' || Object.keys(input).length === 1)), @@ -920,7 +920,7 @@ function resolveOutputJsExtension( type: string = 'commonjs', ): JsExt { if (type === 'module') { - return format === 'cjs' /* || format === 'umd' */ ? 'cjs' : 'js' + return format === 'cjs' || format === 'umd' ? 'cjs' : 'js' } else { return format === 'es' ? 'mjs' : 'js' } @@ -970,10 +970,10 @@ export function resolveBuildOutputs( Object.values(libOptions.entry).length > 1 const libFormats = libOptions.formats || - (libHasMultipleEntries ? ['es', 'cjs'] : ['es' /* , 'umd' */]) + (libHasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']) if (!Array.isArray(outputs)) { - if (/* libFormats.includes('umd') || */ libFormats.includes('iife')) { + if (libFormats.includes('umd') || libFormats.includes('iife')) { if (libHasMultipleEntries) { throw new Error( 'Multiple entry points are not supported when output formats include "umd" or "iife".', @@ -1001,7 +1001,7 @@ export function resolveBuildOutputs( outputs.forEach((output) => { if ( - /* output.format === 'umd' || */ output.format === 'iife' && + (output.format === 'umd' || output.format === 'iife') && !output.name ) { throw new Error( diff --git a/packages/vite/src/node/packages.ts b/packages/vite/src/node/packages.ts index 3ac9fc4284de5c..5d50f285ee3fa5 100644 --- a/packages/vite/src/node/packages.ts +++ b/packages/vite/src/node/packages.ts @@ -273,15 +273,14 @@ export function watchPackageDataPlugin(packageCache: PackageCache): Plugin { return { name: 'vite:watch-package-data', buildStart() { - // watchFile = this.addWatchFile.bind(this) + watchFile = this.addWatchFile.bind(this) watchQueue.forEach(watchFile) watchQueue.clear() }, buildEnd() { watchFile = watchFileStub }, - // TODO: use watchChange hook when implemented - handleHotUpdate({ file: id }) { + watchChange(id) { if (id.endsWith('/package.json')) { invalidatePackageData(packageCache, path.normalize(id)) } diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 503fa3130f5b88..e97df4ed2ffde4 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -360,9 +360,9 @@ export const buildEsbuildPlugin = (): Plugin => { const contentIndex = opts.format === 'iife' ? Math.max(esbuildCode.search(IIFE_BEGIN_RE), 0) - : // : opts.format === 'umd' - // ? esbuildCode.indexOf(`(function(`) // same for minified or not - 0 + : opts.format === 'umd' + ? esbuildCode.indexOf(`(function(`) // same for minified or not + : 0 if (contentIndex > 0) { const esbuildHelpers = esbuildCode.slice(0, contentIndex) res.code = esbuildCode diff --git a/vitest.config.e2e.ts b/vitest.config.e2e.ts index e7b087d24a1bdc..18685bf4f8d1c2 100644 --- a/vitest.config.e2e.ts +++ b/vitest.config.e2e.ts @@ -19,7 +19,6 @@ export default defineConfig({ ? [ './playground/environment-react-ssr/**/*.spec.[tj]s', // needs investigation './playground/external/**/*.spec.[tj]s', // https://github.com/rolldown/rolldown/issues/2041 - './playground/lib/**/*.spec.[tj]s', // umd format './playground/object-hooks/**/*.spec.[tj]s', // object hook sequential './playground/optimize-deps/**/*.spec.[tj]s', // https://github.com/rolldown/rolldown/issues/2031 './playground/tsconfig-json/__tests__/**/*.spec.[tj]s', // decorators is not supported by oxc