1

我正在尝试在 ruby​​ on rails 5.1.4 中使用带有 webpacker的cookieconsent包。

我的 package.json 是

{
  "dependencies": {
    "@rails/webpacker": "3.5",
    "bootstrap": "^4.1.1",
    "cookieconsent": "^3.0.6"
  },
  "devDependencies": {
    "webpack-dev-server": "2.11.2"

我在 app/javascript 中添加了一个 cookieconsent.scss,内容如下

@import 'cookieconsent/build/cookieconsent.min.css'

我正在运行成功编译的 webpack-dev-server,包括处理 cookieconsent.scss 文件即

Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--2-2!node_modules/postcss-loader/lib/index.js??ref--2-3!node_modules/sass-loader/lib/loader.js??ref--2-4!app/javascript/cookieconsent.scss:
       [0] ./node_modules/css-loader??ref--2-2!./node_modules/postcss-loader/lib??ref--2-3!./node_modules/sass-loader/lib/loader.js??ref--2-4!./app/javascript/cookieconsent.scss 10.7 kB {0} [built]
       [1] ./node_modules/css-loader/lib/css-base.js 2.26 kB {0} [built]

在正在加载的 html 页面的头部,我有

<%= stylesheet_pack_tag 'cookieconsent' %>

当我加载页面时,我在 stylesheet_pack_tag 行收到以下错误消息

Webpacker::Manifest::MissingEntryError - Webpacker can't find cookieconsent.css in /Users/Chris/Sites/golf_mentor/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
  "application.css": "/packs/application-4aa426d9718df1187dbf816f0f19f567.css",
  "application.css.map": "/packs/application-4aa426d9718df1187dbf816f0f19f567.css.map",
  "application.js": "/packs/application-157f642ed5e88a31abbb.js",
  "application.js.map": "/packs/application-157f642ed5e88a31abbb.js.map",
  "counter.js": "/packs/counter-9d94c8ee2c39e62e654d.js",
  "counter.js.map": "/packs/counter-9d94c8ee2c39e62e654d.js.map"
}
:
  app/views/pages/temp.html.erb:3:in `block in _app_views_pages_temp_html_erb__4517159242875817520_70136616900600'
  app/views/pages/temp.html.erb:1:in `_app_views_pages_temp_html_erb__4517159242875817520_70136616900600'

我该如何解决?

4

1 回答 1

1

我最终通过使用链轮安装 cookieconsent 解决了这个问题。

然而这篇文章,https: //rubyyagi.com/how-to-use-bootstrap-and-jquery-in-rails-6-with-webpacker/,虽然它没有专门处理 cookieconsent 确实提供了更多关于如何使用 webpacker 安装第三方 css 文件。

于 2020-08-27T22:37:23.513 回答