0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rails6.1 + Webpackerでのデプロイの際のアセットコンパイルでのエラーの対処

Last updated at Posted at 2023-06-07

株式会社TECH LUCKという会社で代表兼エンジニアをしている齊藤です。

前提

Rails6.1 + Webpackerで今更感がありますが、まとめておいたことをせっかくなので公開しました。

# エラーの内容
デプロイの際のアセットコンパイルの際にエラーになってしまい、コンパイルができない状態になっていました。

対処法

config/webpack/loaders/sass.jsを以下の記述で作成します。

config/webpack/loaders/sass.js
module.exports = {
  test: /\.s?css/i,
  use: ['style-loader', 'css-loader', 'sass-loader'],
}

config/webpack/environment.jsに以下の記述を追加して、さきほど作ったsass.jsファイルを読み込ませます。

config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const sass = require('./loaders/sass') //ここを追加

const webpack = require('webpack')
environment.plugins.prepend(
  'Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery',
    Popper: ['popper.js', 'default']
  })
)
environment.loaders.append('sass', sass) //ここを追加
module.exports = environment

これでアセットコンパイルができるようになり、デプロイすることができました。

0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?