Skip to content

Commit

Permalink
Change NODE_ENV defaults (shakacode#185)
Browse files Browse the repository at this point in the history
New logic:

ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
  • Loading branch information
mage1711 authored Sep 8, 2022
1 parent 5a08400 commit a0d34a2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Changes since last non-beta release.

_Please add entries here for your pull requests that are not yet released._
- Fixed NODE_ENV default and moved it from binstubs to the runner [PR 185](https://github.com/shakacode/shakapacker/pull/185) by [mage1711](https://github.com/mage1711).

## [v6.5.1] - August 15, 2022

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ Note, if you are using server-side rendering of JavaScript with dynamic code-spl

Webpacker ships with two binstubs: `./bin/webpacker` and `./bin/webpacker-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` executables to ensure that the right configuration files and environmental variables are loaded based on your environment.

Older Shakapacker installations had the setting of a missing NODE_ENV in the binstubs as the default per RAILS_ENV, it is no longer set there.

#### Automatic Webpack Code Building

Shakapacker can be configured to automatically compile on demand when needed using the `webpacker.yml` `compile` option. This happens when you refer to any of the pack assets using the Shakapacker helper methods. This means that you don't have to run any separate processes. Compilation errors are logged to the standard Rails log. However, this auto-compilation happens when a web request is made that requires an updated webpack build, not when files change. Thus, that can be **painfully slow** for front-end development in this default way. Instead, you should either run the `bin/webpacker --watch` or run `./bin/webpacker-dev-server` during development.
Expand Down
1 change: 0 additions & 1 deletion lib/install/bin/webpacker
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require "webpacker"
require "webpacker/webpack_runner"

ENV["RAILS_ENV"] ||= "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)

APP_ROOT = File.expand_path("..", __dir__)
Expand Down
1 change: 0 additions & 1 deletion lib/install/bin/webpacker-dev-server
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Expand Down
2 changes: 1 addition & 1 deletion lib/webpacker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Webpacker
class Runner
def self.run(argv)
$stdout.sync = true

ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
new(argv).run
end

Expand Down

0 comments on commit a0d34a2

Please sign in to comment.