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

Cloning the production configuration to a staging environment #1301

Closed
jnimety opened this issue Feb 27, 2018 · 7 comments
Closed

Cloning the production configuration to a staging environment #1301

jnimety opened this issue Feb 27, 2018 · 7 comments

Comments

@jnimety
Copy link

jnimety commented Feb 27, 2018

What is the recommended way to clone the production environment configuration in @rails/webpacker/environments/production.js to another environment? I'd like to guarantee that our staging environment is identical to production even if @rails/webpacker/environments/production.js changes.

@rossta
Copy link
Member

rossta commented Feb 27, 2018

I'm not quite sure what you mean by clone, but if you mean that you'd like to use the same Webpack configuration in both production and staging environments, I can think of a couple separate options below. These are both based on the fact that the Webpacker executables expect a file in config/webpack whose name matches the NODE_ENV and exports a valid Webpack configuration (source).

  1. Set NODE_ENV=production when running webpack compilation for your staging servers. If your deploy process runs the compilation on the remote server, then you'd set the env there. This will ensure that the production webpack config is loaded for the build step.

  2. Set the NODE_ENV=staging instead (or let it default to staging, assuming that's the RAILS_ENV value you're using) and add a file, config/webpack/staging.js that simply imports and re-exports the production config. You'll also want to add a staging entry to config/webpacker.yml that simply appends the production yaml settings.

@jnimety
Copy link
Author

jnimety commented Feb 27, 2018

Thanks. Yes, option 2 is what I had in mind but I've been unsuccessful. I think this is what you're suggesting, and I'll test, but does it look right to you?

// config/webpack/staging.js
module.exports = require('./production')

@jnimety
Copy link
Author

jnimety commented Feb 27, 2018

I think the problem with this is that webpacker internally loads @rails/webpacker/environments/NODE_ENV.js, so it's still looking for staging.js and falling back to the default.

@rossta
Copy link
Member

rossta commented Feb 27, 2018

What is the error you're getting? Did you add a staging entry to config/webpacker.yml to match production? This works for me using the latest Webpacker.

@rossta
Copy link
Member

rossta commented Feb 28, 2018

Looks like there's also work being done in #1304 to make this easier.

@jnimety
Copy link
Author

jnimety commented Feb 28, 2018

no errors but I think the issues is that https://github.com/rails/webpacker/blob/master/package/index.js#L11 loads files based on NODE_ENV. So if NODE_ENV=staging then @rails/webpacker/environments/production.js will not be loaded, correct?

@gauravtiwari
Copy link
Member

Please try 3.3.0

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