Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Support onBuildRead option #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion lib/requirejs/rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def initialize(application)
uglify
uglify2
useStrict
wrap
wrapShim
}
end

Expand Down Expand Up @@ -133,6 +133,9 @@ def user_config=(cfg)
if url = cfg.delete('baseUrl')
raise Requirejs::ConfigError, "baseUrl is not needed or permitted in the configuration"
end
# delete any cached configs, will be lazily resolved
self.delete(:build_config)
self.delete(:run_config)
self[:user_config] = cfg
end

Expand Down
6 changes: 5 additions & 1 deletion lib/requirejs/rails/rjs_driver.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var requirejs = require(<%= rjs_path.to_s.dump %>)
var baseConfig = <%=
cdn_pattern = Regexp.new("\\Ahttps?://")

modifiedHash = build_config.select { |k, _| k != "modules" }
modifiedHash = build_config.select { |k, _| k != "modules" && k != "onBuildRead"}
pathsHash = modifiedHash["paths"]
modifiedHash["dir"] = build_dir.to_s
modifiedHash["paths"] = Hash[
Expand All @@ -14,6 +14,10 @@ modifiedHash["paths"] = Hash[
JSON.pretty_generate(modifiedHash)
%>;

<% if build_config["onBuildRead"] %>
baseConfig.onBuildRead = <%= build_config["onBuildRead"] %>
<% end %>

baseConfig.modules = [
<% build_config["modules"].each do |m| %>
<%= JSON.pretty_generate(m) %>,
Expand Down