Webpacker 在 *Rails 6* 应用程序的 manifest.json 中找不到 application.css [英] Webpacker throws application.css not found in manifest.json in *Rails 6* application

查看:57
本文介绍了Webpacker 在 *Rails 6* 应用程序的 manifest.json 中找不到 application.css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我们的应用程序使用 Rails 6.它在生产中运行良好,但在开发模式下会引发一些错误.请帮助我.

Currently we use Rails 6 for our application. It's working fine in production but in development mode it throws some errors. Please assist me.

这就是我的 application.js 和 application.css 的样子

This is how my application.js and application.css looks like

packs/application.js

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("jquery")

import '../stylesheets/application'
import './bootstrap_custom.js'
import './side_menu.js.erb'
//import './sweetalert.js'
import './business_hours.js'
import './admin.js'
import './services.js'
import './user_service.js' 

包/样式表/application.scss

@import './bootstrap_custom.scss';

$fa-font-path: '~@fortawesome/fontawesome-free/webfonts'; 
@import '~@fortawesome/fontawesome-free/scss/fontawesome';
@import '~@fortawesome/fontawesome-free/scss/solid';
@import './admin_dashboard.scss';
@import './side_menu.css';
@import './fonts.scss'; 
@import './login.css';

推荐答案

经过长时间的努力,我找到了解决方案.谢谢@ahmed kamal.

After a long struggle I found a solution for this. Thanks @ahmed kamal.

多个名称相同但扩展名不同的包.

Multiple packs with the same name but a different extension.

即: application.scss 和 application.js 只有最后一个会进入 webpack 入口路径配置.

i.e: application.scss and application.js only the last one will make it to the webpack entry path configuration.

解决方案:

 1. Rename stylesheets/application.scss into stylesheets/style.scss
 2. Import style.scss in application.js like this import '../stylesheets/style'
 3. config/webpacker.yml make below changes
      compile: true
      cache_manifest: true
      extract_css: true

如果此解决方案不适合您,请尝试

If this solution not working for you, try th

rake assets:precompile

这对我来说一切正常

这篇关于Webpacker 在 *Rails 6* 应用程序的 manifest.json 中找不到 application.css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆