Light Build and Webpack 2 still load all highlight.js languages
See original GitHub issueHi folks.
Thank you for this awesome package.
Today I was to raise an issue related wit bundle size.
I am trying to use the light build as you can see in the following code
import SyntaxHighlighter, { registerLanguage } from "react-syntax-highlighter/dist/light"
import foundation from 'react-syntax-highlighter/dist/styles/foundation';
['javascript', 'php', 'xml', 'bash', 'markdown', 'json', 'yaml'].forEach((langName) => {
const langModule = require(`react-syntax-highlighter/dist/languages/${langName}`);
registerLanguage(langName, langModule);
});
But when you use Webpack 2 to create a package, the tree shaking logic doesn’t work as you can see in the following image.
I asked in webpack forums, and people mentioned that maybe internally maybe all languages are included.
I tried also trying to exclude with the same result
new webpack.IgnorePlugin(/^\.\/lib\/languages$/, /highlight\.js/),
I would really appreacite any recommendation.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14
Top Results From Across the Web
Light Build and Webpack 2 still load all highlight.js languages
I am trying to use the light build as you can see in the following ... Light Build and Webpack 2 still load...
Read more >How to use highlight.js
The bare minimum to auto-detect the language and highlight some code. // load the library and ALL languages hljs = require('highlight.js'); html =...
Read more >Reducing bundle size of Highlight.js with Webpack
Though importing only the languages we need from Highlight isn't supported out of the box, Webpack can help us make a build that...
Read more >Goodbye, Prettify. Hello highlight.js! Swapping out our Syntax ...
We still support all the Prettify language aliases you know and love, along with the new aliases from highlight.js. However, we are not...
Read more >Highlight.js syntax highlighting not working after webpack build
I figured out the answer whilst posting, but figure the solution might be helpful to someone. The only anomaly between production and dev ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe when you do a dynamic require like that, webpack can’t determine what to include so it just includes the whole folder of the static string part of your require. Try switching to just 7 static imports and see if that solves the problem.
@stereokai webpack-bundle-analyzer