From d8dd4460144e63a9120290631c492aba3cbea332 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Sat, 24 Mar 2018 14:02:50 +0000 Subject: [PATCH] Remove NODE_ENV declaration from rake task and production flag (#1377) --- .rubocop.yml | 2 +- lib/tasks/webpacker/compile.rake | 16 ++++++++-------- lib/webpacker.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index daafc21de..393d0f0fd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -115,7 +115,7 @@ Style/UnneededPercentQ: # Align `end` with the matching keyword or starting expression except for # assignments, where it should be aligned with the LHS. -Lint/EndAlignment: +Layout/EndAlignment: Enabled: true EnforcedStyleAlignWith: variable diff --git a/lib/tasks/webpacker/compile.rake b/lib/tasks/webpacker/compile.rake index 4a9056422..84f7355c0 100644 --- a/lib/tasks/webpacker/compile.rake +++ b/lib/tasks/webpacker/compile.rake @@ -1,5 +1,3 @@ -ENV["NODE_ENV"] ||= "production" - $stdout.sync = true def ensure_log_goes_to_stdout @@ -23,12 +21,14 @@ end namespace :webpacker do desc "Compile JavaScript packs using webpack for production with digests" task compile: ["webpacker:verify_install", :environment] do - ensure_log_goes_to_stdout do - if Webpacker.compile - # Successful compilation! - else - # Failed compilation - exit! + Webpacker.with_node_env("production") do + ensure_log_goes_to_stdout do + if Webpacker.compile + # Successful compilation! + else + # Failed compilation + exit! + end end end end diff --git a/lib/webpacker.rb b/lib/webpacker.rb index a2bfd47d8..a58563d90 100644 --- a/lib/webpacker.rb +++ b/lib/webpacker.rb @@ -13,6 +13,14 @@ def instance @instance ||= Webpacker::Instance.new end + def with_node_env(env) + original = ENV["NODE_ENV"] + ENV["NODE_ENV"] = "production" + yield + ensure + ENV["NODE_ENV"] = original + end + delegate :logger, :logger=, :env, to: :instance delegate :config, :compiler, :manifest, :commands, :dev_server, to: :instance delegate :bootstrap, :clobber, :compile, to: :commands