Skip to content
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

Set NODE_ENV var when running Encore scripts #747

Open
wants to merge 3 commits into
base: master
from

Conversation

@javiereguiluz
Copy link
Member

javiereguiluz commented Mar 24, 2020

Q A
License MIT
Doc issue/PR -

In a project I needed to enable PurgeCSS only when in production. This is done in postcss.config.js and there's no way to know if Encore is running in production or not. I asked on Slack and @Lyrkan proposed this solution to me. It worked for me nicely!

As I think this could be useful to others, I propose this change in case it makes sense to make it in general for all projects.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request passes validation.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request passes validation.

"dev-server": "NODE_ENV=development encore dev-server",
"dev": "NODE_ENV=development encore dev",
"watch": "NODE_ENV=development encore dev --watch",
"build": "NODE_ENV=production encore production --progress"
Comment on lines 11 to 14

This comment has been minimized.

Copy link
@Lyrkan

Lyrkan Mar 24, 2020

Contributor

For portability reasons something like cross-env should also probably be used.

This comment has been minimized.

Copy link
@weaverryan

weaverryan Mar 28, 2020

Member

Yes, if we do this, then we need to use cross-env. I was always hoping to avoid that.

An alternative might be documentation? Couldn't we advise people to set this env var (of some other env var) inside webpack.config.js if they want to? Like:

// webpack.config.js
process.env. NODE_ENV = Encore.isProduction() ? 'production' : 'development';

WDYT?

This comment has been minimized.

Copy link
@javiereguiluz

javiereguiluz Mar 31, 2020

Author Member

I made some changes according to your comments. What do you think? Thanks.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request passes validation.

Copy link
Contributor

symfony-flex-server bot left a comment

Pull request passes validation.

@@ -1,5 +1,9 @@
var Encore = require('@symfony/webpack-encore');

// Optional: sync the NODE_ENV value with the current webpack environment
// It's useful when you configure tools like PostCSS in their own config files instead of in webpack.config.js.

This comment has been minimized.

Copy link
@weaverryan

weaverryan Apr 5, 2020

Member

I’d change this to:

It’s useful if you need to read the environment from some other config file

The key difference is that I want people to know that this change doesn’t cause any behavior to change, it’s just something you can use if you want yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.