节点模块CSS导入路径在开发中起作用,但在生产中不起作用
我正在使用Jsbundling-Rails& CSSSBUNDLING轨道。
我有一个文件夹,该文件夹从类似供应商的供应商中导入CSS库:
@import "drift-zoom/dist/drift-basic.min.css";
@import "dropzone/dist/min/dropzone.min.css";
@import "select2/dist/css/select2.css";
但是我会遇到类似的错误:
ActionController::RoutingError (No route matches [GET] "/assets/select2/dist/css/select2.css"):
问题似乎是在寻找资产中的这些文件,而当它应该在root Directory的Node_modules文件夹中查找时。
我有rails.application.config.assets.paths<< rails.root.join('node_modules')
in config/initializers/initializers.rb
my package.json csss for css是:
"build:css": "sass ./app/assets/stylesheets/application.sass.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
I am moving from Webpack to esbuild with jsbundling-rails & cssbundling-rails.
I have a folder which imports css libraries from vendors like so:
@import "drift-zoom/dist/drift-basic.min.css";
@import "dropzone/dist/min/dropzone.min.css";
@import "select2/dist/css/select2.css";
However I get errors like:
ActionController::RoutingError (No route matches [GET] "/assets/select2/dist/css/select2.css"):
The problem seem that it is looking for theses file in assets, when instead it should be looking in the node_modules folder at the root directory.
I have Rails.application.config.assets.paths << Rails.root.join('node_modules')
in config/initializers/assets.rb
My package.json script for css is:
"build:css": "sass ./app/assets/stylesheets/application.sass.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在
config/Environments/production.rb
中对我有帮助:config.assets.compile = true
this helped for me in
config/environments/production.rb
:config.assets.compile = true
我发现问题是这些库正在尝试导入CSS文件,我想我的SASS实现无法处理。我管理着为大多数库找到SCSS版本,然后使用这些版本,现在可以使用这些SCSS版本。
如果找不到替代方案,则不确定如何导入CSS文件。如果您有建议,请评论
I discovered that the issue was that these libraries were trying to import css files, which I guess could not be handled by my sass implementation. I mananaged to find scss versions for most of the libraries and used these instead, and it now works.
Not sure what the solution is for importing css files if an alternative cannot be found. Please comment if you have a suggestion