3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rails 6 に Bootstrap3 導入

Last updated at Posted at 2019-09-29

1. yarn で Bootstrap と jquery を導入する

$ yarn add bootstrap-sass jquery

2. app/config/webpack/environment.js に jquery が使えるように設定追加

app/config/webpack/environment.js
const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
environment.plugins.append('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery'
  })
)

module.exports = environment

3. app/javascript/packs/application.js に 以下追記

app/javascript/packs/application.js
import '../javascripts/application.js'
import '../stylesheets/application.scss'

4. app/javascript/stylesheets/application.scss に以下追記

app/javascript/stylesheets/application.scss
// bootstrap-sass 内部で 相対パスを解決できないため、パス変数を差し替え
$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";

@import "~bootstrap-sass/assets/stylesheets/_bootstrap.scss"

5. app/javascript/javascripts/application.js に以下追記

app/javascript/javascripts/application.js
import 'bootstrap-sass';
3
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?