Rails6 jQuery introduced

bash


$ yarn add jquery

config/webpack/environment.js


const { environment } = require('@rails/webpacker');

const webpack = require('webpack');

environment.plugins.append('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery/src/jquery',
    jQuery: 'jquery/src/jquery'
  })
);

module.exports = environment;

app/javascript/packs/application.js


//add to
require('jquery');

OK if the version is displayed on the console of the developer tools.

console


console.log($.fn.jquery);
// 3.5.1

Recommended Posts

Rails6 jQuery introduced
Rails Bootstrap introduced
[Rails] Introducing jquery
Introduced Rails6 toastr
[Rails] Use jQuery
[Rails] Introduced debugging gems'better_errors' and'binding_of_caller'
Introduced graph function with rails
Introduced gRPC client to rails
How to deploy jQuery on Rails
Enable jQuery and Bootstrap in Rails 6 (Rails 6)
[Ruby on Rails] Introduced paging function
How to introduce jQuery in Rails 6
Timeless search with Rails + JavaScript (jQuery)
[Rails g.error]
Rails basics
Rails Review 1
Rails API
Rails migration
Introduced jacoco
[Rails] first_or_initialize
rails tutorial
About Rails 6
Introduced Vue.js to an existing Rails app
Rails foundation
Rails memorandum
rails tutorial
rails tutorial
rails tutorial
Preparing to introduce jQuery to Ruby on Rails
[Rails] devise
rails tutorial
rails tutorial
Rails Tips
rails method
rails tutorial
How to use credentials.yml.enc introduced in Rails 5.2
Introduced Vuetify to an existing Rails app
[Rails] ActiveRecord
[Rails] form_with
Rails Review 2
How to use JQuery in js.erb of Rails6