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

Commit cf0989d

Browse files
committed
When assets aren't precompiled, search for modules based on their user-defined paths before using the module name
1 parent 3650c16 commit cf0989d

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,39 @@ def requirejs_include_tag(name = nil, &block)
4949
end
5050

5151
if Rails.application.config.assets.digest
52-
modules = requirejs.build_config['modules'].map { |m| requirejs.module_name_for m }
52+
assets_precompiled = !Rails.application.config.assets.compile
53+
modules = requirejs.build_config["modules"].map {|m| requirejs.module_name_for m}
54+
user_paths = requirejs.build_config["paths"] || {}
5355

5456
# Generate digestified paths from the modules spec
5557
paths = {}
56-
modules.each { |m| paths[m] = javascript_path(m).sub /\.js$/, '' }
5758

58-
if run_config.has_key? 'paths'
59+
modules.each do |module_name|
60+
script_path = if !assets_precompiled
61+
# If modules haven't been precompiled, search for them based on their user-defined paths before using the
62+
# module name.
63+
user_paths[module_name] || module_name
64+
else
65+
# If modules have been precompiled, the script path is just the module name.
66+
module_name
67+
end
68+
69+
paths[module_name] = javascript_path(script_path).gsub(/\.js$/, "")
70+
end
71+
72+
if run_config.has_key? "paths"
5973
# Add paths for assets specified by full URL (on a CDN)
60-
run_config['paths'].each do |k, v|
74+
run_config["paths"].each do |k, v|
6175
paths[k] = v if v.is_a?(Array) || v =~ /^(https?:)?\/\//
62-
6376
end
6477
end
6578

6679
# Override user paths, whose mappings are only relevant in dev mode
6780
# and in the build_config.
68-
run_config['paths'] = paths
81+
run_config["paths"] = paths
6982
end
7083

71-
run_config['baseUrl'] = base_url(name)
84+
run_config["baseUrl"] = base_url(name)
7285

7386
html.concat(content_tag(:script) do
7487
script = "require.config(#{run_config.to_json});"

0 commit comments

Comments
 (0)