Skip to content

Set NODE_ENV var when running Encore scripts #747

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

Closed
wants to merge 4 commits into from

Conversation

javiereguiluz
Copy link
Member

@javiereguiluz 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

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@javiereguiluz
Copy link
Member Author

@Lyrkan @weaverryan what do you think about this proposal after the latest changes that you suggested? Should we add this or close it as "won't fix"? Thanks!

Copy link
Contributor

@Lyrkan Lyrkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about this proposal after the latest changes that you suggested?

Let's go with this.
It may not always work depending on how the process that reads the other config file is called/implemented but it should be OK for most use cases.

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

// Optional: sync the NODE_ENV value with the current Webpack Encore environment
// It’s useful if you need to read the Webpack Encore environment from some other config file
// process.env.NODE_ENV = Encore.isProduction() ? 'production' : 'development';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be moved after the Manually configure the runtime environment case

@seb-jean
Copy link
Contributor

I love this idea :)

@nicolas-grekas
Copy link
Member

Please rebase so that the new checks can run.
See also @stof's comment.

@nicolas-grekas nicolas-grekas deleted the webpack-env-vars branch February 13, 2022 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants