Skip to content

Commit

Permalink
Remove NODE_ENV declaration from rake task and production flag (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravtiwari authored Mar 24, 2018
1 parent d418bcf commit d8dd446
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions lib/tasks/webpacker/compile.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ENV["NODE_ENV"] ||= "production"

$stdout.sync = true

def ensure_log_goes_to_stdout
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/webpacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8dd446

Please sign in to comment.