2017-01-05 101 views
0

我有一些.coffee文件,我已將webpack配置爲包含這些文件。eslint webpack解析器不起作用

// inside `webpack.config.js`... 

resolve: { 
    // tell webpack which extensions to auto search when it resolves modules. With this, 
    // you'll be able to do `require('./utils')` instead of `require('./utils.js')` 
    extensions: ['', '.js', '.coffee', '.jsx'], 
    // by default, webpack will search in `web_modules` and `node_modules`. Because we're using 
    // Bower, we want it to look in there too 
    modulesDirectories: ['node_modules', 'bower_components'], 

    alias: { 
    'jquery.ui.widget': 'jquery-ui/ui/widget.js', 
    'jquery-ui/widget': 'jquery-ui/ui/widget.js', 
    'jquery-ui-css': 'jquery-ui/../../themes/base' 
    } 
}, 

我已經安裝eslint-import-resolver-webpack到我的項目,在我.eslintrc.json文件中設置它:

"settings": { 
    "import/parser": "babel-eslint", 
    "import/resolver": { 
     "webpack": { "config": "webpack.config.js" } 
    } 
}, 

出於某種原因,不過,我還是會得到這樣一行import/no-unresolved掉毛錯誤:

import foo from './my-coffee-file' 

其中在目錄內有my-coffee-file.coffee

關於發生什麼問題的任何想法?

回答

1

我的問題是因爲我的項目的目錄結構...

config 
|__webpack.config.js 
| 
frontend 
|__package.json 
|__all the JS/coffee files 

所以,我需要明確指向的WebPack配置文件:

"settings": { 
    "import/resolver": { 
     "webpack": { "config": "../config/webpack.config.js" } 
    } 
} 

../是必要的,因爲它開始搜索找到package.json,這對我來說就是在frontend目錄中。