Comme j'ai souvent utilisé jquery dans le développement d'applications, j'ai résumé la méthode d'introduction. ** La version Rails est 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'
})
)
#Jusque là
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