You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use Vite@v6 to package [email protected] to output IIFE format code. The code built in Vite@v5 contains named exports, but these named exports are lost with Vite@v6, leaving only a default export.
The output above is just a different version of Vite. Using the same code, it is as follows
import{createRequire}from'node:module';import{build}from'vite';constrequire=createRequire(import.meta.url);exportasyncfunctionbuildPackage(){// Call the build function with build configurationsconstresult=awaitbuild({// Do not use a configuration fileconfigFile: false,build: {// Do not output fileswrite: false,lib: {// Entry file is the specified package pathentry: require.resolve('path-to-regexp'),// Convert package name to camel casename: 'pathToRegexp',// Output format is iifeformats: ['iife'],// Output file name is the same as the package namefileName: 'path-to-regexp',},rollupOptions: {output: {// Export method is named exportexports: 'named',// Allow extension of existing global variablesextend: true,},},// Do not minifyminify: false,},});// Check if result is an array, if so, take the first element, otherwise use result directlyconst_result=Array.isArray(result) ? result[0] : result;// If the _result does not have an output property, returnif(!('output'in_result)){return;}return_result.output[0].code;}console.log(awaitbuildPackage());console.log(`Hello Node.js v${process.versions.node}!`);
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
The README doesn't say about IIFE, but it seems output.exports: 'default' works as well.
When bundling to CommonJS, i.e output.format === 'cjs', make sure that you do not set output.exports to 'named'. The default value of 'auto' will usually work, but you can also set it explicitly to 'default'. That makes sure that Rollup assigns the default export that was generated for your CommonJS entry point to module.exports, and semantics do not change.
Describe the bug
I use Vite@v6 to package [email protected] to output IIFE format code. The code built in Vite@v5 contains named exports, but these named exports are lost with Vite@v6, leaving only a default export.
Here are the links to reproduce in v5 and v6:
The output above is just a different version of Vite. Using the same code, it is as follows
Reproduction
https://stackblitz.com/edit/stackblitz-starters-qsvdae?file=index.js
Steps to reproduce
Please
npm run build
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: