LoginSignup
0
0

More than 1 year has passed since last update.

jQuery導入

Posted at

今回は、JavaScriptのjQuerykの導入のみの記事です!
ネットで調べても中々うまくできなかったので、、、

※jQueryの導入には、jquery-railsというGemを利用することもあります!
今夏は違う方法です

◇jQueryをインストール

ターミナル
% yarn add jquery

jQueryを管理化に

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

environment.plugins.prepend('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery',
    jquery: 'jquery',
  })
)

module.exports = environment

jQueryを認識させる??

 app/javascript/packs/application.js
require('jquery')

下記内容は記述されてればそのままで!

 app/views/layouts/application.html.erb
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

これでjQuery使えます!

以上

0
0
0

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
0
0