highlightjs / vue-plugin

Highlight.js Vue Plugin
BSD 3-Clause "New" or "Revised" License
200 stars 28 forks source link

Does the plugin support vite v3.1.9? #43

Closed libsgh closed 1 year ago

libsgh commented 1 year ago

Dev works fine, but when i use vite build, andvite preview, it doesn't show any style, and no error output.

import 'highlight.js/styles/atom-one-light.css'
import 'highlight.js/lib/common'
import hljsVuePlugin from "@highlightjs/vue-plugin"
export default({
  name: "code",
  components:{
    highlightjs: hljsVuePlugin.component
  }
})

image

xiaomaiyun commented 1 year ago

https://github.com/highlightjs/vue-plugin/issues/38

xiaomaiyun commented 1 year ago

I have temporarily solved this problem. The reason is that webpack did not pack the unused code when packing, so quotes it here.

import 'highlight.js/styles/atom-one-dark.css'
import hljsCommon from 'highlight.js/lib/common'
import hljsVuePlugin from '@highlightjs/vue-plugin'
. . . 
const app = createApp(App)
. . .
// 注意:解决Vue使用highlight.js build打包发布后样式消失问题,原因是webpack在打包的时候没有把未被使用的代码打包进去,因此,在此处引用一下,看似无意义实则有用
hljsCommon.highlightAuto('<h1>Highlight.js has been registered successfully!</h1>').value
app.use(hljsVuePlugin)
. . .
joshgoebel commented 1 year ago

I wonder if import hljs from 'highlight.js/lib/common' would work?

xiaomaiyun commented 1 year ago

I wonder if import hljs from 'highlight.js/lib/common' would work?

hljsCommon.highlightAuto('<h1>Highlight.js has been registered successfully!</h1>').value

work,if this code

libsgh commented 1 year ago

I wonder if import hljs from 'highlight.js/lib/common' would work?

hljsCommon.highlightAuto('<h1>Highlight.js has been registered successfully!</h1>').value

work,if this code

It's work for me, thanks.