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.

Should support tree-shaking in production

See original GitHub issue

if you import style from app.css.ts

// app.css.ts
export const styleA = style({
  display: 'flex'
})
export const styleB = style({ // no used
  display: 'flex'
})
// App.tsx
import { styleA } from './app.css.ts'
export const App = () => {
   return <div className={styleA}/>

It’s surprising that vanilla extract doesn’t do any tree-shaking which means both styleA and styleB will all include in the CSS bundle

Maybe related to these code https://github.com/seek-oss/vanilla-extract/blob/aebf9349371d631a38145df70c7de40643843554/packages/integration/src/processVanillaFile.ts#L94-L99

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pakholeung37commented, Nov 9, 2022

@ddhp I did not use PurgeCSS as a plugin. Instead I wrote a script and run it after build. Check my repo https://github.com/pakholeung37/loft-mix/search?q=purgecss

0reactions
ddhpcommented, Nov 9, 2022

For now, I am using PurgeCSS to do the job, I works fine!

Hi I am trying to get tree shaking to work with PurgeCSS, but it would remove all the style.

Here is the minimal reproduce repo https://stackblitz.com/edit/vercel-next-js-cidu1b?file=README.md

Have I missed something?

next.js native css-module is working fine

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree Shaking - webpack
The sideEffects and usedExports (more known as tree shaking) optimizations are two different things. sideEffects is much more effective since it allows to...
Read more >
Tree-Shaking: A Reference Guide - Smashing Magazine
Tree-shaking” is a must-have performance optimization when bundling JavaScript. In this article, we dive deeper on how exactly it works and ...
Read more >
Should support tree-shaking in production · Issue #700 - GitHub
Tree shaking is a bundler feature, we can't implement it inside of vanilla-extract. However, vanilla-extract does generate code that can be tree ...
Read more >
Tree shaking and code splitting in webpack - LogRocket Blog
Tree shaking, also known as dead code elimination, is the practice of removing unused code in your production build.
Read more >
Reduce JavaScript payloads with tree shaking - web.dev
In production builds, webpack can be configured to "shake" off exports from ES6 modules that weren't explicitly imported, making those production builds ...
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