Skip to content

Set NODE_ENV to Rails.env #58

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

Merged
merged 1 commit into from
Mar 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/browserify-rails/browserify_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ def dependencies
end
end

# Environtment to run browserify in:
#
# NODE_PATH https://nodejs.org/api/all.html#all_loading_from_the_global_folders
# but basically allows one to have multiple locations for non-relative requires
# to be resolved to.
#
# NODE_ENV is set to the Rails.env. This is used by some modules to determine
# how to build. Example: https://facebook.github.io/react/downloads.html#npm
def env
{
"NODE_PATH" => asset_paths,
"NODE_ENV" => Rails.env
}
end

# Run the requested version of browserify (browserify or browserifyinc)
# based on configuration or the use_browserifyinc parameter if present.
#
Expand Down Expand Up @@ -142,7 +157,6 @@ def run_browserify(logical_path=nil, extra_options=nil, force_browserifyinc=nil)

# Compose the full command (using browserify or browserifyinc as necessary)
command = "#{browserify_command(force_browserifyinc)} #{command_options} -"
env = { "NODE_PATH" => asset_paths }

# The directory the command will be executed from
base_directory = File.dirname(file)
Expand Down
12 changes: 12 additions & 0 deletions test/browserify_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ class BrowserifyProcessorTest < ActiveSupport::TestCase
assert_equal "-d -i test4.js", @processor.send(:options)
end

test "env should have NODE_ENV set" do
assert_equal Rails.env, @processor.send(:env)["NODE_ENV"]
end

test "env should have NODE_PATH set to Rails.application.config.assets.paths" do
node_env = @processor.send(:env)["NODE_PATH"]

Rails.application.config.assets.paths.each do |path|
assert_equal true, node_env.include?(path)
end
end

def stub_engine_config(key, value)
@processor.send(:config).stubs(key).returns(value)
end
Expand Down