如何将VUE3组件库作为独立的Web组件?
我在VITE架构中有一组VUE3组件,并希望将它们作为纯Web组件的Lib发布。如何使用我的构建文件进行?
我跟随Vite文档建立了一个自由。它说要将其添加到vite.config.js文件中:
const path = require('path');
const {defineConfig} = require('vite');
const vue = require('@vitejs/plugin-vue');
// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/components/index.js'),
name: 'TykaynLib',
fileName: (format) => `tykayn-lib.${format}.js`,
},
rollupOptions: {
external: ['vue'],
output: {
// Provide global variables to use in the UMD build
// Add external deps here
globals: {
vue: 'Vue',
TykaynLib : 'TykaynLib'
},
},
},
},
plugins: [vue()],
});
因此,在构建后,我将获得包含我组件的ES和UMD文件,但它们不是独立的,他们要求Vuejs能够工作。
我想要纯Web组件,只需加载脚本并只需要在HTML文件中添加我的自定义HTML标签即可使用它们。我不想为VUE制作插件,也不想要求组件的最终用户必须使用VUE。 有办法建立这个吗?
I have a set of Vue3 components in a Vite architecture and want to publish them as a lib of pure web components. how can i use my built files to do so ?
I followed the Vite docs to build a lib. It says to add this in the vite.config.js file:
const path = require('path');
const {defineConfig} = require('vite');
const vue = require('@vitejs/plugin-vue');
// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/components/index.js'),
name: 'TykaynLib',
fileName: (format) => `tykayn-lib.${format}.js`,
},
rollupOptions: {
external: ['vue'],
output: {
// Provide global variables to use in the UMD build
// Add external deps here
globals: {
vue: 'Vue',
TykaynLib : 'TykaynLib'
},
},
},
},
plugins: [vue()],
});
So after the build i get ES and UMD files containing my components, but they are not standalone, they require VueJS to be able to work.
I wanted pure web components that i could use by just loading a script and having to just add my custom HTML tags inside an HTML file. I do NOT want to make a plugin for vue or require the end users of my components to have to use Vue.
Is there a way to build this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论