2016-04-25 25 views
1

webpackでCSSファイルをインポートするのが渋滞しています。私はこのエラーが発生し続ける:Webpackが私のCSSファイルを見つけられません

ERROR in ./index.js 
Module not found: Error: Cannot resolve 'file' or 'directory' ../style/style.css in c:\developement\prja/app 
@ ./index.js 11:0-29 

私はstyle.cssのためのあらゆる種類のパスを試しました。 'css!../style/style.css''/style/style.css'または'./style/style.css'のように動作しますが、いずれも機能しません。私はまた、インポートの代わりにrequireを使用しようとしました。しかし、私は同じエラーメッセージが表示され続けます。

アイデア?

マイindex.jsエントリポイントファイルは、次のようになります

import 'expose?$!expose?jQuery!jquery'; 
import angular from 'angular'; 
import 'bootstrap-webpack'; 
import '../style/style.css'; 

var ngModule = angular.module('app', []); 

アンこれは私のwebpack.config.jsです:

module.exports = { 
    context: __dirname + '/app', 
    entry: './index.js', 
    output: { 
     path: __dirname + '/app', 
     filename: 'bundle.js' 
    }, 
    module: { 
     loaders: [ 
      { 
       test: /\.js$/, 
       exclude: /node_modules/, 
       loader: "babel-loader" 
      }, 
      { 
       test: /\.css$/, 
       loader: 'style-loader!css-loader' 
      }, 
      {test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'}, 
      {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'}, 
      {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'}, 
      {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'} 
     ] 
    } 

}; 

そして、これは私のファイルsctructureです:

| lighthouse.iml 
| package.json 
| webpack.config.js 
| 
+---app 
|  index.html 
|  index.js  
|    
\---style 
     style.css 
+1

あなたの 'context:__dirname + '/ app''のためです。この場合、webpackは常に '/ app'フォルダを探し始めます。解決方法あなたのスタイルフォルダをappに移動するか、コンテキストプロパティーから '/ app'を削除してください –

+0

ありがとう、それで問題は解決しました。私はそれを受け入れるために答えとしてこれを自由に追加してください。 – BetaRide

答えて

0

contextプロパティとファイル構造に関する問題が発生しました。

context - エントリオプションを解決するための基本ディレクトリ(絶対パス!)はwebpack docsです。言い換えれば、これはwebpackがあなたのアプリを探し始めるフォルダです。 - >context: __dirnameまたはあなたもあなたのweblack.configファイルからcontextを削除することができ

  • がにあなたのスタイルフォルダを移動し

    1. contextプロパティから/appを削除します。ここではそれを修正する方法2つの方法がありますアプリフォルダ

    Th anks!

  • 関連する問題