You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I investigated a few issues (e.g. highlightjs/vue-plugin#44) reported in the vue-plugin repo where production builds are stripping out import 'highlight.js/lib/common'; side effect imports
Turns out vite (which uses rollup internally) tree shakes side effect imports if the files themselves are not marked as side effect in package.json
Sample Code or Instructions to Reproduce
npm create vite@latest
npm install highlight.js
Then inside src/main.ts, add:
import 'highlight.js/lib/common'
import hljs from 'highlight.js/lib/core'
console.log(hljs.listLanguages())
In debug builds npm run dev, it should list all languages registered inside highlight.js/lib/common
However in production builds npm run build && npm run preview, it will print an empty array.
Expected behavior
Should print all languages in both debug/production builds
However, it'll only work as long as the hljs variable is used/referenced the current file. I still think it's a good idea to mark that file as side effect to prevent production builds from "randomly" breaking if that variable ever stops being referenced.
Describe the issue/behavior that seems buggy
I investigated a few issues (e.g. highlightjs/vue-plugin#44) reported in the
vue-plugin
repo where production builds are stripping outimport 'highlight.js/lib/common';
side effect importsTurns out vite (which uses rollup internally) tree shakes side effect imports if the files themselves are not marked as side effect in
package.json
Sample Code or Instructions to Reproduce
Then inside
src/main.ts
, add:In debug builds
npm run dev
, it should list all languages registered insidehighlight.js/lib/common
However in production builds
npm run build && npm run preview
, it will print an empty array.Expected behavior
Should print all languages in both debug/production builds
Additional context
This package.json should be updated to:
The text was updated successfully, but these errors were encountered: