I have a question regarding using Vite to package a Vue project as a library #12284
Unanswered
xinxianwu
asked this question in
Help/Questions
Replies: 3 comments
-
I recently created a Vue package, and maybe my Vite config could help you: import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import dts from 'vite-plugin-dts';
import libCss from 'vite-plugin-libcss';
import svgLoader from 'vite-svg-loader';
export default defineConfig({
plugins: [
vue(),
dts({
insertTypesEntry: true,
tsconfigPath: './tsconfig.json'
}),
libCss(),
svgLoader({
defaultImport: 'url'
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
build: {
target: 'es2015',
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'VueJsCodeBlock',
fileName: 'index',
formats: ['es']
},
rollupOptions: {
external: [
'vue',
'src/components/generate-prism-languages/**/*',
'src/components/generate-prism-languages/node_modules/*'
],
output: {
globals: {
vue: 'Vue' // Global variable for Vue
},
exports: 'named' // Control export style
}
}
}
}); For more details, you can check out my package here: https://github.com/Hetari/vuejs-code-block/ Note: I’m aware that my file structure isn’t ideal right now; I plan to improve it in the future. |
Beta Was this translation helpful? Give feedback.
0 replies
-
运行过程中没有报错吗,看看错误信息呢 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I also use Vite to bundle Vue and TypeScript into a library. You can refer to the linked resource above for reference. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a question regarding using Vite to package a Vue project as a library. I configured vite.config.json to package the project as a library with main.js as the entry point, and then referenced this library in a .NET Core project. However, I can't seem to find the exported methods as I expected. Does anyone know what might be causing this issue?"
Beta Was this translation helpful? Give feedback.
All reactions