Skip to content

Commit 02c4757

Browse files
authored
(doc): Fix usage of highlight.js/lib/common (#20)
Modern bundlers will optimize out unused imported names. Importing the module directly will indicate that it is a side effect and should not be optimized out. Fix #18
1 parent 365d616 commit 02c4757

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ Note: The plugin imports `highlight.js/lib/core` internally (but no languages).
5959
You can also simply load all "common" languages at once (as of v11):
6060

6161
```js
62-
import hljs from 'highlight.js/lib/common';
62+
import 'highlight.js/lib/common';
6363
import hljsVuePlugin from "@highlightjs/vue-plugin";
6464

6565
const app = createApp(App)
6666
app.use(hljsVuePlugin)
6767
app.mount('#app')
6868
```
6969

70+
Note that the `highlight.js/lib/common` import does not import the `hljs` object because it registers common languages internally and modern web bundlers like `webpack` will optimize out unused imported names. If you want to customize the `hljs` object, you can import it like the [previous example](#using-es6-modules--bundling).
71+
7072
## Using component locally
7173

7274
```vue
@@ -78,7 +80,7 @@ app.mount('#app')
7880
</template>
7981
8082
<script>
81-
import hljs from 'highlight.js/lib/common';
83+
import 'highlight.js/lib/common';
8284
import hljsVuePlugin from "@highlightjs/vue-plugin";
8385
8486
export default {

0 commit comments

Comments
 (0)