Closed totszwai closed 2 years ago
My comment in that issue was referring to a WIP Microbundle 1.0, not the 0.14 release.
170kb of JS for icons seems like a lot of JS - are you bundling SVGs into JavaScript files?
My comment in that issue was referring to a WIP Microbundle 1.0, not the 0.14 release.
Oh. :(
are you bundling SVGs into JavaScript files
Yes. bundling SVG into React component. Is there a way to speed it up? :D
While it's probably not the answer you're looking for, ideally, you don't want to be importing SVGs as JS. It's horrifically expensive to do so and there better ways to consume, such as <img>
, <defs>/<use>
, etc.
@rschristian Could you point me to the better practices to on how to use img
, defs
or use
? The reason why I am using microbundle and converting them into React object is so that we could use it in our React TS code, ex:
import { MySpecialIcon } from '@blah/icons`;
...
<MySpecialIcon />
Similar to how Material UI bundling their icons.
All you need is a loader to return a URL for the asset on an import like the following:
import React from 'react';
import ReactLogo from './logo.svg';
const App = () => {
return (
<div className="App">
<img src={ReactLogo} alt="React Logo" />
</div>
);
}
@rschristian While that could be a solution, we are using svgr
(https://react-svgr.com/) to convert SVGs into React component. The main reason is that we don't wanna deal with svg directly. Is there anything such as spawning extra job processes to speed up the bundling?
Is there an ETA on the v1.0 release? :)
I get that's what you're currently doing, but SVGR is a pretty awful solution. You're paying a huge JS cost when none is required essentially.
I can't speak to the time length issue here, or any ETA, just wanted to point out that you could avoid the issue entirely as well as improve perf and UX considerably by going an alternative route.
Is there an ETA on the v1.0 release? :)
Sorry, but no
Re: https://github.com/developit/microbundle/issues/513
The above issue was closed stating that there would be improvements in the next release, so I switched to 0.14 today hoping that it would speed things up, but nope. :(
Command ran without
raw
:microbundle --jsx 'React.createElement' --jsxImportSource react --globals react/jsx-runtime=jsx --no-compress --format modern,cjs
With
raw
:microbundle --raw --jsx 'React.createElement' --jsxImportSource react --globals react/jsx-runtime=jsx --no-compress --format modern,cjs
With actually timed: