LoginSignup
0

More than 1 year has passed since last update.

railsにwebpackerを導入する方法

Last updated at Posted at 2022-03-14

railsにwebpackerがない場合、導入する方法を紹介します。

※ 注意

Rails7.0.0からwebpackerがなくなったので無理に導入するとエラーの元となります。

なので一番良いのはバージョンを下げてアプリを作成することです。

先にバージョンのインストールの説明を載せておきます。

バージョンを指定したアプリ作成の例

terminal
rails _6.X.X_ new  sampleapp

webpackerをインストールするにはyarnを先にインストールしておく必要があります。

brewよりnpmでyarnをインストールした方がいいそうです。

まず最初にrailsのアプリを作成した状態にしておきます。

railsのアプリが作成できたら

rails の gemfile に 以下を入力します。

gemfile
gem 'webpacker', '~> 4.0'

次にターミナルでアプリファイルの場所でbundle installと入力します、

terminal
bundle install

最後にターミナルでrails webpacker:installと入力します。

terminal
rails webpacker:install

これでrailsにwebpackerが導入されました。

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