子文件夹安装中的源映射路径错误

My subfolder install kept giving errors in Firefox console about the fact that it is unable to find source maps.

Source map error: request failed with status 404 Resource URL: [https://redacted.com/community/assets/admin-…1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js](https://redacted.com/community/assets/admin-e1c3cbc1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js) Source Map URL: /assets/admin-e1c3cbc1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js.map

As you can see, the /community path prefix is missing from the source map URL.

So I did a little digging.

lib/tasks/assets.rake does this:

  assets = cdn_relative_path("/assets")
  source_map_root = assets + ((d = File.dirname(from)) == "." ? "" : "/#{d}")

Now cdn_relative_path in lib/global_path.rb looks like this.

module GlobalPath
  def path(p)
    "#{GlobalSetting.relative_url_root}#{p}"
  end

  def cdn_path(p)
    GlobalSetting.cdn_url.blank? ? p : "#{GlobalSetting.cdn_url}#{path(p)}"
  end

  def upload_cdn_path(p)
    if SiteSetting.Upload.s3_cdn_url.present?
      p = Discourse.store.cdn_url(p)
    end

    (p =~ /^http/ || p =~ /^\/\//) ? p : cdn_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

As you can see, both cdn_path and upload_cdn_path eventually call the path method which makes sure that the subfolder is being prefixed. However, cdn_relative_path does not call the path method, it just returns its parameter (called… path).

BTW I think cdn_path needs to return path(p) in the middle part of the ternary as well?

1 个赞

@sam is the expert on source maps

@david has fussed with this in the past, but yeah getting the paths right for CDN + subfolder is not easy. I am open to a PR that fixes it provided this is very targeted at your magic combo and does not regress any places that work now.

3 个赞

@sam 针对这个源映射错误的问题,我们有什么解决方案吗?我在子目录安装和 Fastly CDN 环境下也遇到了同样的问题。

我的建议是稍作等待,我们正迁移至 Ember CLI,它将取代整个流水线。

2 个赞

@sam 我们什么时候迁移到 Ember CLI?我们在子目录安装和 Fastly CDN 方面遇到了同样的问题。

此迁移正在进行中,您现在即可使用 Ember CLI 在本地进行开发,预计还需数月时间完成。

2 个赞

我认为这应该用 ember-cli 来解决?@david 你知道是不是这样吗?

2 个赞

在过去的几周里,我对 source-map 进行了多项改进,这些改进同时适用于“旧版”和 Ember-CLI 管道。

我检查了我们在 tests-passed 上托管的一个子文件夹站点,情况似乎有了很大改善 :ok_hand:

5 个赞

此主题已在 12 天后自动关闭。不再允许回复。