尽管CSS文件存在于packs目录中,但stylesheet_pack_tag不会生成任何输出

时间:2019-07-10 21:33:34

标签: ruby-on-rails vue.js webpacker

随着Rails的最新更新,我们的VueJS客户端应用程序的stylesheet_pack_tag停止产生输出。 Webpacker 确实/public/packs文件夹中生成CSS文件(JS文件和其他文件旁边)。 javascript_pack_tag语句工作正常,但是以某种方式stylesheet_pack_tag仍然无效。我可能会忽略什么?

1 个答案:

答案 0 :(得分:0)

一些调试使我得到了想要的答案。事实证明,以前在 Webpacker 3.2.0 宝石中,stylesheet_pack_tag如下所示:

def stylesheet_pack_tag(*names, **options)
  unless Webpacker.dev_server.running? && Webpacker.dev_server.hot_module_replacing?
    stylesheet_link_tag(*sources_from_pack_manifest(names, type: :stylesheet), **options)
  end
end

在新的 Webpacker 4.0.X 宝石中,stylesheet_pack_tag如下所示:

def stylesheet_pack_tag(*names, **options)
  if current_webpacker_instance.config.extract_css?
    stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
  end
end

首先是罪魁祸首:仅当webpacker.yml包含extract_css: true时,此语句才起作用,就像这样:

default: &default
  # Extract and emit a css file
  extract_css: true

当然,您也可以针对开发,测试或生产级别进行设置。

事后看来,the Webpacker 3.5 to 4 upgrade docs已经提到了此更改(第一段中的第6点)以及in this paragraph