-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library build does not work for UMD/IIFE bundles when Vite detects code that can be code-split #2982
Comments
Any updates on this? |
i have the same problem..... |
Just tested this with the latest version (2.3.7) and can confirm this bug is still present |
Just using // vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, "src/main.js"),
name: "ViteUmdBug"
},
rollupOptions: {
external: ["vue"],
output: {
inlineDynamicImports: true, // <== here the entry
globals: {
vue: "Vue"
}
},
}
},
plugins: [vue()]
}) output: yarn run v1.22.10
warning package.json: No license field
$ vite build
building for production...
✓ 7 modules transformed.
dist/style.css 0.20kb / brotli: 0.12kb
dist/vite-umd-bug.es.js 10.67kb / brotli: 7.36kb
dist/vite-umd-bug.umd.js 10.40kb / brotli: 7.19kb
Done in 0.66s. |
Thanks for the tip @userquin , that does indeed fix the immediate problem of being able to build. |
you can add 2 outputs, I will test it and feed back here... |
Right of course. We can't use code splitting with UMD builds as the error message clearly indicates. |
ok, you can use this configuration: // vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, "src/main.js"),
name: "ViteUmdBug"
},
rollupOptions: {
external: ["vue"],
output: [{
format: "esm",
esModule: true,
exports: "named",
globals: {
vue: "Vue"
}
}, {
format: "umd",
inlineDynamicImports: true,
interop: "esModule",
exports: "named",
globals: {
vue: "Vue"
}
}],
}
},
plugins: [vue()]
}) |
you can see it on my fork |
what do you want is to export // vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, "src/components/HelloWorld.vue"),
name: "HelloWorld"
},
rollupOptions: {
external: ["vue"],
output: [{
format: "es",
esModule: true,
exports: "named",
globals: {
vue: "Vue"
}
}, {
format: "umd",
inlineDynamicImports: true,
interop: "esModule",
exports: "named",
globals: {
vue: "Vue"
}
}],
}
},
plugins: [vue()]
}) |
I have the same problem, none of the above solutions/configs worked |
Describe the bug
When building a library (utilizing
build.lib
), Vite tries to code-split the generated UMD (and presumably also IIFE) bundle, which fails with the message UMD and IIFE output formats are not supported for code-splitting builds.This is only a problem when building a library and when Vite detects points in the code that can be code-split (e.g. a dynamic
import
).Reproduction
https://github.com/Robin-Hoodie/vite-umd-bug
This is a scaffolded Vite project using
vue
.I updated
vite.config.js
to build in library mode based on the instructions in the documentationI also added a dynamic
import
insrc/App.vue
to introduce code splittingI used
vite@2.0.0
in the reproduction, but can confirm this is also an issue withvite@2.1.5
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: yarn
Logs
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: