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

Webpacker::Env.current cannot be changed when using NODE_ENV and spring #205

Closed
activefx opened this issue Mar 30, 2017 · 4 comments
Closed

Comments

@activefx
Copy link

Webpacker::Env.current cannot be changed with NODE_ENV after initial load when using spring (unless spring is disabled or stopped).

Steps to reproduce

Using webpacker master branch (3564a1c) with Rails 5.1.0.rc1

Expected behavior

RAILS_ENV=development rake webpacker:compile
#=> Webpacker::Env.current
#=> "development"

NODE_ENV=test rake webpacker:compile
#=> Webpacker::Env.current
#=> "test"

Actual behavior

RAILS_ENV=development rake webpacker:compile
#=> Webpacker::Env.current
#=> "development"

NODE_ENV=test rake webpacker:compile
#=> Webpacker::Env.current
#=> "development"

System configuration

Rails version:
5.1.0.rc1
Ruby version:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
Webpacker:
3564a1c

@mfazekas
Copy link

Can't you just use RAILS_ENV=test rails webpacker:compile or RAILS_ENV=test rake webpacker:compile? I assume those are working.

@gauravtiwari
Copy link
Member

gauravtiwari commented Mar 30, 2017

@activefx Yes as @mfazekas pointed out please use RAILS_ENV as it's refreshed on the fly. You can read more here - https://github.com/rails/spring#commands . The other option is to use something like figaro or dotenv and have spring watch them for changes - https://github.com/rails/spring#watching-files-and-directories

# inside an initializer
Spring.watch 'config/application.yml'

The last option would be to restart spring if you change NODE_ENV

@gauravtiwari
Copy link
Member

Perhaps, we could do this too?

if defined?(Spring)
  Spring.after_fork do
    # Reload 
    Webpacker::Env.load
  end
end

@dhh
Copy link
Member

dhh commented Apr 4, 2017

Closed by #221

@dhh dhh closed this as completed Apr 4, 2017
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

4 participants