-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
How to use third-party libraries? #603
Comments
Just create a file import DefaultTheme from 'vitepress/theme'
import { install } from 'element-plus'
import 'element-plus/dist/index.css'
export default {
...DefaultTheme,
enhanceApp({ app }) {
install(app)
}
} This is documented here: https://vitepress.vuejs.org/guide/theming.html#extending-the-default-theme and mentioned at https://vitepress.vuejs.org/guide/differences-from-vuepress.html#general (last difference). Refer brc-dd/vitepress-element-plus-demo for complete example. |
thanks~ |
Im trying to demo my In import DefaultTheme from "vitepress/theme";
import Plugin from "../../../src/plugin";
export default {
...DefaultTheme,
enhanceApp({ app }: any) {
app.use(Plugin, {
clientId: import.meta.env.VITE_SOME_ENV,
});
},
}; This works fine in the dev mode. On build, it throws an error since my plugin registers a component that uses I tried removing all the references to any of the components and still issue is there |
OK resolved it using import DefaultTheme from "vitepress/theme";
export default {
...DefaultTheme,
async enhanceApp({ app }: any) {
if (!import.meta.env.SSR) {
const plugin = await import("../../../src/plugin");
app.use(plugin.default ?? plugin, {
clientId: import.meta.env.VITE_SOME_ENV,
});
}
},
}; |
This works, but with the following warning - what does this mean?
|
When you install it like that, it doesn't code split. The bundle will include lot of unused JS/CSS. It is recommended to use Here I had done this for Arco Design, you just need to change vite.config and update deps there: https://github.com/brc-dd/vitepress-with-arco |
I tried the steps, but can't seem to get the auto-imports working. Could you help me figure out what's it that I've missed? Neither the element-plus, nor the custom component is getting loaded. The source is https://github.com/akil-rails/vitepress-with-element-plus
|
@akil-rails Do it like this: // docs/vite.config.js
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default {
plugins: [
AutoImport({
include: [/\.vue$/, /\.md$/],
resolvers: [ElementPlusResolver({ ssr: true })]
}),
Components({
dirs: ['components'],
include: [/\.vue$/, /\.md$/],
resolvers: [ElementPlusResolver({ ssr: true })]
})
]
} |
Thanks! The component import is working ( I notice that vite.config.js needs to be in docs\ - i thought that project root was ..\docs) ) But there are still issues -
Committed the updated code at https://github.com/akil-rails/vitepress-with-element-plus. |
The base file of theme is not loading when |
The theme loads with ssr: false, but yes, then pnpm build fails with the following error
Is this related ? - antfu-collective/vite-ssg#232 |
ESM is not supported on VitePress now anyway. I was using Vite 3 version, there the error was different: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".css"
It can be, though I doubt this is an issue with vite-ssg. Feel free to create a separate issue here, I'll take a look if I get time. |
Okay - will do..Thanks! |
Is #476 (comment) related ?
|
@akil-rails Is it working fine? And, no it doesn't skip SSR. It will sort of transpile |
pnpm build gives a warning
& the styling for the table is a bit-off , but at-least it builds. Committed the code at https://github.com/akil-rails/vitepress-with-element-plus. Could you have a look if you get time? |
The large chunk warning is gone too, but still I can see 20+ components (earlier were 150+) in the generated file, maybe they depend on each other, that should be fine IG. Regarding that charset warning, it's fine to ignore it. If you wanna suppress this, you can remove charset by adding something like this: vitejs/vite#5079 (comment) in your vite.config (or postcssrc if you have one) Also, regarding that no external thing, it was needed in case of arco too. |
Thanks - that removed the warning - should we close #1164 ? Committed to https://github.com/akil-rails/vitepress-with-element-plus. |
No, let's keep it open. It should probably work without noExternal in Vite 3 version, but it isn't. We need to track that. We won't be tracking ssr: true thing (no base styles) because it has something to do with unplugin-vue-components' element plus resolver. I might create an issue there later. |
Is your feature request related to a problem? Please describe.
Before, I want to use the third-party component library element-plus in vuepress, which can be directly in clientAppEnhance.ts folder for app Use(). The code is as follows:
So how do I use third-party libraries in vitepress?
Describe the solution you'd like
I hope to supplement the detailed configuration of the document. Now the content of the document configuration of vitepress is too few, and it is difficult for novices to get started with vitepress
Describe alternatives you've considered
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: