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

running webpack when NODE_ENV=test #1429

Closed
ciampam9 opened this issue Apr 13, 2018 · 4 comments
Closed

running webpack when NODE_ENV=test #1429

ciampam9 opened this issue Apr 13, 2018 · 4 comments

Comments

@ciampam9
Copy link

ciampam9 commented Apr 13, 2018

👋 Hey all!

Is there a reason why we're not allowing webpack to run environment/test.js? It seems as though when running NODE_ENV=test ./bin/webpack, the nodeEnv in package/env.js is being overridden to production.

Currently, if the node env isn't a part of the whitelist (package/env.js):

const NODE_ENVIRONMENTS = ['development', 'production']
const DEFAULT = 'production'

it defaults to production (package/env.js):

module.exports = {
  railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
  nodeEnv: nodeEnv && NODE_ENVIRONMENTS.includes(nodeEnv) ? nodeEnv : DEFAULT
}

Would it be possible to whitelist test as well? If the package has a specific test environment we should be allowed to use it by setting the node env, imo.

I realize this is outlined in the docs but why would we still have a package/environments/test.js file if you cannot run it?

@gauravtiwari
Copy link
Member

@ciampam9 Apologies for late reply. Good question - basically I wanted to remove it in this PR #1359 but totally forgot in the end. If you check out that PR I have explained the reasons for only having development and production for NODE_ENV.

In earlier versions of webpacker we have used Rails env as fallback env, which isn't ideal because both NODE_ENV and RAILS_ENV has different meaning for different environments.

For example: setting NODE_ENV=production means the webpacker will compile assets in production mode however at same time RAILS_ENV can be staging. Webpack and node libraries only understands development and production environments. However, it's normal to have many custom RAILS_ENV.

For your use case you could do, since now RAILS_ENV is used for loading configurations:

# NODE_ENV is development by default
RAILS_ENV=test ./bin/webpack

or you could use

RAILS_ENV=test bundle exec rails webpacker:compile
RAILS_ENV=test bundle exec rails assets:precompile

@DougPuchalski
Copy link

@gauravtiwari Not sure if this is the same issue but even when I set RAILS_ENV=test I get output files in my packs and not packs-test as configured in my webpacker.yml, so it seems to be using NODE_ENV which is overridden to production when selecting the config

@gauravtiwari
Copy link
Member

@aceofspades What version of webpacker are you using?

@DougPuchalski
Copy link

@gauravtiwari Found my issue, looks like I wasn't in sync with the gem & node package. Interesting, would be nice if this condition were detected, it caused quite a bit of debug time

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

No branches or pull requests

3 participants