如何使用导入地图在铁轨中添加引导和jQuery?

发布于 2025-02-08 21:42:42 字数 706 浏览 2 评论 0原文

我是设置Rails 7应用程序。而且我不想使用导入地图添加Bootstrap和jQuery。我会尝试但不起作用。如果我犯了任何错误,请遵循此步骤,请纠正。

  1. Rails新的演示
  2. 捆绑安装安装
  3. 使用索引创建演示控制器,并添加一些自举代码。
  4. 然后,我运行此命令bin/importmap pin bootstrap

so。在导入地图中添加了这两行 PIN“ Bootstrap”,to:“ https://ga.jspm.io/npm:< a href =” //cdn-cgi/l/lim/email-protection“ class” class =“ __ cf_email__” data-cfemail =“电子邮件&nbsp;受保护] /dist/js/bootstrap.esm.js” pin“@popperjs/core”,to:“ https://ga.jspm.io/npm:@popperjs/< a href =”/cdn-cgi/l/l/email-protection class =“ __ cf_email__” data-cfemail =“ D7B4B8A5B297E5F9E6E6F9E2”> [email&nbsp; procepted] /lib/index.js“

如果我已经在importmap.rb文件中pin bootstrap。为什么它不起作用,或者我错过了一些饱受的才能。

感谢您的重播。

I'm setup rails 7 app. And i wan't to add bootstrap and jquery using import map. I'll try but didn't work. I follow this step if i made any mistake please correct.

  1. rails new demo
  2. bundle install
  3. create demo controller with index and add some bootstrap code.
  4. Then i run this command bin/importmap pin bootstrap

So. in Import map added this two line
pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js"
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/[email protected]/lib/index.js"

If i already pin bootstrap in importmap.rb file. Why it's not working or i missing some configration.

Thanks for replay.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友谊不毕业 2025-02-15 21:42:42

请检查您的以下文件具有相应的内容:

// app/stylesheets/application.bootstrap.scss

@import 'bootstrap/scss/bootstrap';
@import 'bootstrap-icons/font/bootstrap-icons';
# package.json

{
  "dependencies": {
    "bootstrap": "^5.1.3",
    "sass": "^1.50.0"
  },
  "scripts": {
    "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
  }
}
# app/javascript/application.js

import * as bootstrap from "bootstrap"
# config/importmap.rb

pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js"
# app/views/layouts/application.html.{erb|slim|haml}

<head>
  <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
  <%= javascript_importmap_tags %>
</head>

并使用bin/dev命令运行服务器

,以安装jQuery运行bin/importMap pin jquery command并将其导入application.js文件

# app/javascript/application.js

import { $, jQuery } from 'jquery'

// export for others scripts to use
window.$ = $
window.jQuery = jQuery

Please check that you have following files with corresponding content:

// app/stylesheets/application.bootstrap.scss

@import 'bootstrap/scss/bootstrap';
@import 'bootstrap-icons/font/bootstrap-icons';
# package.json

{
  "dependencies": {
    "bootstrap": "^5.1.3",
    "sass": "^1.50.0"
  },
  "scripts": {
    "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
  }
}
# app/javascript/application.js

import * as bootstrap from "bootstrap"
# config/importmap.rb

pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.esm.js"
# app/views/layouts/application.html.{erb|slim|haml}

<head>
  <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
  <%= javascript_importmap_tags %>
</head>

And run server with bin/dev command

To install JQuery run bin/importmap pin jquery command and import it in application.js file

# app/javascript/application.js

import { $, jQuery } from 'jquery'

// export for others scripts to use
window.$ = $
window.jQuery = jQuery
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文