eslint webpack 解析器不起作用
eslint webpack resolver doesn't work
我有一些 .coffee
文件,我已将 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
像这样的行的 linting 错误:
import foo from './my-coffee-file'
目录中有 my-coffee-file.coffee
。
有什么问题吗?
我的问题是由于我的项目的目录结构...
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
目录中。
我有一些 .coffee
文件,我已将 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
像这样的行的 linting 错误:
import foo from './my-coffee-file'
目录中有 my-coffee-file.coffee
。
有什么问题吗?
我的问题是由于我的项目的目录结构...
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
目录中。