Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Tree-shaking not working #688
Comments
|
That's because it's not possible for current bundlers/minifiers to detect if const Foo = /* #__PURE__ */ styled("div")`
color: red;
`For a babel plugin that does inserts these comments check out: |
|
just trying to understand it in detail. // library.js
function useMyHook(){...} // current bundlers/minifiers don't know whether useMyHook is pure or not
export function ComponentWithHook(){
const [a,b] = useMyHook();
// do something with a & b
...
}
export function IAmPure(){...}// app1.js
import {ComponentWithHook} from 'library';
render(<ComponentWithHook/>)// app2.js
import {IAmPure} from 'library';
render(<IAmPure/>)In above case
@marvinhagemeister ^ which option(s) is correct ? |
|
@kuldeepkeshwar Maybe just try it out? The top level exports aren't the only requirement for tree-shaking. Tree-shaking is a subclass of dead code elimination (=DCE) and it's only possible to remove something when the minifier/bundler is 100% certain that removing it won't alter the program. For todays bundlers this usually translates to checking if the code in question has no side-effects. If the body of a function can't be proven to be pure and is used somewhere, it won't be removed. |
layout-ui is bundled using
mircobundleand produces cjs/esm/umd bundles.While using any of named export from
layout-ui, the final application bundle contains wholeesmbundle fromlayout-ui.e.g
In above example, ideally it should only bundle code for
Stack.