FIX: when CDN assets are not in root path source maps fail
This commit is contained in:
parent
0ef141b2c3
commit
886273f158
|
@ -6,4 +6,13 @@ module GlobalPath
|
|||
def cdn_path(p)
|
||||
"#{GlobalSetting.cdn_url}#{path(p)}"
|
||||
end
|
||||
|
||||
def cdn_relative_path(path)
|
||||
if (cdn_url = GlobalSetting.cdn_url).present?
|
||||
URI.parse(cdn_url).path + path
|
||||
else
|
||||
path
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -102,8 +102,8 @@ end
|
|||
|
||||
def compress_node(from,to)
|
||||
to_path = "#{assets_path}/#{to}"
|
||||
|
||||
source_map_root = (d=File.dirname(from)) == "." ? "/assets" : "/assets/#{d}"
|
||||
assets = cdn_relative_path("/assets")
|
||||
source_map_root = assets + (d=File.dirname(from)) == "." ? "" : "/#{d}"
|
||||
source_map_url = cdn_path "/assets/#{to}.map"
|
||||
|
||||
cmd = "uglifyjs '#{assets_path}/#{from}' -p relative -c -m -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '#{source_map_url}'"
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
require 'rails_helper'
|
||||
require 'global_path'
|
||||
|
||||
class GlobalPathInstance
|
||||
extend GlobalPath
|
||||
end
|
||||
|
||||
describe GlobalPath do
|
||||
|
||||
context 'cdn_relative_path' do
|
||||
def cdn_relative_path(p)
|
||||
GlobalPathInstance.cdn_relative_path(p)
|
||||
end
|
||||
|
||||
it "just returns path for no cdn" do
|
||||
expect(cdn_relative_path("/test")).to eq("/test")
|
||||
end
|
||||
|
||||
it "returns path when a cdn is defined with a path" do
|
||||
GlobalSetting.expects(:cdn_url).returns("//something.com/foo")
|
||||
expect(cdn_relative_path("/test")).to eq("/foo/test")
|
||||
end
|
||||
|
||||
it "returns path when a cdn is defined with a path" do
|
||||
GlobalSetting.expects(:cdn_url).returns("https://something.com:221/foo")
|
||||
expect(cdn_relative_path("/test")).to eq("/foo/test")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue