Tag: Rails6/jQuery
yarn add jquery
const { environment } = require('@rails/webpacker') //ここから const webpack = require('webpack') environment.plugins.prepend('Provide', new webpack.ProvidePlugin({ $: 'jquery/src/jquery', jQuery: 'jquery/src/jquery' }) ) //ここまで module.exports = environment
require("@rails/ujs").start() require("turbolinks").start() require("@rails/activestorage").start() require("channels") require("jquery") // ←の1行を追加 // (後略)
$(function() { console.log("test"); });
require("@rails/ujs").start() require("turbolinks").start() require("@rails/activestorage").start() require("channels") require("jquery") require("test.js") // ←の1行を追加
function hello() { window.alert('hello world') } -app/assets/config/manifest.jsを編集。javascriptsの行を追加。 #pre{{ /= link_tree ../images //= link_directory ../stylesheets .css //= link_directory ../javascripts .js}}
<button onclick="hello()">Hello!</button>