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 3 years have passed since last update.

webpackのCSSのbackground-imageのpath問題を解決する

Last updated at Posted at 2022-04-08

概要

webpackで背景画像を出力する際にパスで詰まってしまったので備忘録メモ

buildした際にパスが書き換わってしまうので、config.jsをいじる必要があるんだけど解決方法がわからず放置してましたが、英語文献を読めば即解決しました。
今思えばすごく簡単だった・・・

以下のように options: { publicPath: '../' },を下記加えればOK

ソース

ディレクトリ構成
/dist
 └css/style.css
 └img/hoge.jpg
/src
 └scss/style.scss
 └img/hoge.jpg
webpack.config.js
      {
        test: /\.(css|scss|sass)$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: { publicPath: '../' },
          },
          {
            loader: 'css-loader',
            options: { sourceMap: true },
          },
          {
            loader: 'sass-loader',
          },
        ],
      },

参考記事

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?