2017-02-09 6 views
0

WebpackでSCSSを使用しています。私は背景の画像でいっぱいにしたいdivを持っています。私はHTMLでそれをハードコーディングする場合:SCSSのバックグラウンドイメージが動作しない - `webpackMissingModule`エラー

<div class="plus-icon" 
    style="background-image: url('graphics/plus-icon.png');"> 
</div> 

すべてがOKですが、私はそのようにSCSSを経由して、それを設定しようとすると:

Uncaught Error: Cannot find module "./graphics/plus-icon.png" 
> webpackMissingModule @ 

/* ... */ 

./~/css-loader!./~/sass-loader!./src/stylesheets/main.scss 
Module not found: Error: Cannot resolve 'file' or 'directory' 
./graphics/plus-icon.png in /home/karol/GitProjects/monterail-test/src/stylesheets 
resolve file 
/home/karol/GitProjects/monterail-test/src/stylesheets/graphics/plus-icon.png 
doesn't exist 

/* ... */ 

として:私はこのようなエラーを得た

.plus-icon { 
    background-image: url('graphics/plus-icon.png'); 
} 

Webpackは私のPNGをあまりにも早くロードしようとし、与えられたパスを間違って解釈しようとします。

どうすれば修正できますか?

+1

このソリューションを確認したことがありますか? http://stackoverflow.com/questions/38834508/webpack-not-loading-background-image –

+0

ありがとう - しかし、これは私の問題を解決しません。私はコンパイル中に私の写真にリンクしたいのではなく、そのままCSSの解釈のために残しておきます。 –

+0

私のアイコンのコピーを 'stylesheets/graphics/plus-icon.png'の場所に追加すると、解釈中に別の奇妙なエラーが発生します:' ERROR in ./src/stylesheets/graphics/plus-icon.png モジュール解析失敗しました:/home/karol/GitProjects/monterail-test/src/stylesheets/graphics/plus-icon.png予期しない文字 ' '(1:0) このファイルタイプを処理するには、適切なローダーが必要な場合があります。 SyntaxError:予期しない文字 ' '(1:0) ' –

答えて

0

HTMLファイルに対してではなく、SCSSファイルのパスを基準にして作成する必要があります。

+0

小さな例が参考になるかもしれません。 – GhostCat

関連する問題