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.

`NODE_ENV` equals `development` in PostCSS during `vite build`

See original GitHub issue

Describe the bug

I’m trying to use purge css plugin with PostCSS, but I’ve noticed that it doesn’t work automatically because the NODE_ENV is set to development instead of production during vite build.

Reproduction

https://github.com/KubaJastrz/vite-postcss-node-env-repro

  1. clone the repo
  2. install deps - yarn
  3. build production bundle - yarn build
  4. observe "development" being logged (coming from tailwind.config.js)
  5. generated css file is over 1MB, while it should be much smaller after purging unused classes

System Info

  • required vite version: 1.0.0-rc.4
  • required Operating System: windows 10
  • required Node version: 12.11.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
daychongyangcommented, Aug 13, 2020

Or, you can use the .env file in a specific mode to specify the value of NODE_ENV.

In package.json you can just make it like the code below:

{ 
    "scripts": {
        "dev": " vite --mode=development",
	"build": "vite build --mode=production",
    }
}

In .env.development

NODE_ENV=development

In .env.production

NODE_ENV=production

Related source code

1reaction
KubaJastrzcommented, Aug 12, 2020

Thanks @mitchbne. That’s exactly what I did in my project for the time being.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Vite
Base public path when served in development or production. ... Entries will be defined as globals during dev and statically replaced during build....
Read more >
Output - webpack
The top-level output key contains a set of options instructing webpack on how and where it should output your bundles, assets, and anything...
Read more >
Vite - Next generation web build tools - YouTube
Vite.js, a JavaScript development server that significantly improves the frontend ... Most notably, Vite serves your source files over na...
Read more >
How to solve my problem? (npm run build) - Laracasts
npm run build > build > vite build vite v3.1.0 building for production. ... during build: TypeError: [postcss] Cannot read properties of undefined...
Read more >
nodeenv · PyPI
js virtual environment) is a tool to create isolated node.js environments. It creates an environment that has its own installation directories, that doesn't ......
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