I often used jquery in application development, so I summarized the introduction method. ** Rails version is 6.0.0. ** **
yarn add jquery
config/webpack/environment.js
const { environment } = require('@rails/webpacker')
#Postscript
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery'
})
)
#So far
module.exports = environment
app/javascript/packs/application.js
require('jquery') #Postscript
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("../category")
require("../category_post")
Recommended Posts