-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce bundle size #56
Comments
@ajGingrich We have this option, check out our docs - https://react-highlight.neostack.com/docs/optimisation |
I am already using this in my code and I still have the large bundle size.
Does this not work with |
Did you configured your webpack as per the docs ? |
Sorry to keep opening and closing this, I've got a deadline at work so I thought I wouldn't be able to get to it anytime soon. Yes, I configured it like in the docs and I can make it work if I copy it locally but I need to remove this line
and replace it with:
taken from here |
There is a mistake in the docs. We have to import a different file: import Highlight from 'react-highlight/lib/optimized';
// instead of
import Highlight from 'react-highlight'; |
There is some more info on optimising the build in this closed PR #35. Would be great if this info was more available in the docs. For anyone looking to optimise on the latest version of Gatsby, here's an approach that seems to work. As mentioned above, import the optimised package when using React Highlight then specify the language available. import Highlight from 'react-highlight/lib/optimized'
return () => (
<Highlight languages={['javascript']}>{someCode}</Highlight>
) Then in exports.onCreateWebpackConfig = ({ stage, actions, plugins }) => {
if (stage === 'build-javascript') {
actions.setWebpackConfig({
plugins: [
plugins.contextReplacement(/highlight\.js\/lib\/languages$/, new RegExp(`^./(javascript)$`)),
],
})
}
} |
I realize that highlight.js has a very large bundle but I suggest passing an array prop to define the languages they want to import. My highlight.js currently takes up 539kb parsed size and 188kb gzipped. This is over half of my bundle and six times more than react.
I should be able to work on this in the upcoming weeks.
The text was updated successfully, but these errors were encountered: