question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Light Build and Webpack 2 still load all highlight.js languages

See original GitHub issue

Hi 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. all-languajes-includes

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:closed
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
bmathewscommented, Jun 2, 2017

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.

1reaction
Kobzolcommented, Aug 14, 2018

@stereokai webpack-bundle-analyzer

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found