Javascript Next.js-Eslint在开发模式下不刷新任何页面(除了pages/_app.js)
我在使用Next.js设置eslint时遇到问题。当我运行Javascript Next.js-Eslint在开发模式下不刷新任何页面(除了pages/_app.js),javascript,reactjs,webpack,eslint,next.js,Javascript,Reactjs,Webpack,Eslint,Next.js,我在使用Next.js设置eslint时遇到问题。当我运行next build时,它实际上会正确地lint我的所有文件,但当我在开发模式(next)下运行应用程序时,eslint实际上只lintpages/\u app.js,而完全忽略我的所有其他文件(例如pages/index.js) 我的next.config.js如下所示: module.exports = { webpack: (config, { buildId, dev, isServer, defaultLoaders, we
next build
时,它实际上会正确地lint我的所有文件,但当我在开发模式(next
)下运行应用程序时,eslint实际上只lintpages/\u app.js
,而完全忽略我的所有其他文件(例如pages/index.js
)
我的next.config.js
如下所示:
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (dev) {
config.module.rules.push({
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
loader: 'eslint-loader',
})
}
return config
},
}
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/prop-types": 0,
"react/react-in-jsx-scope": 0
}
};
而.eslintrc.js
看起来是这样的:
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (dev) {
config.module.rules.push({
test: /\.(j|t)sx?$/,
exclude: /node_modules/,
loader: 'eslint-loader',
})
}
return config
},
}
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/prop-types": 0,
"react/react-in-jsx-scope": 0
}
};
是否有一个示例项目演示如何使用Next.js设置eslint?Eslint几乎是任何现代JS web应用程序的标准,因此我惊讶地发现文档或任何演示项目中都没有提到Eslint。好的,我发现了问题,在开发模式下的next.JS实际上不会删除任何页面,直到您尝试将其加载到浏览器中。因此,如果您在
页面/index.js
上出现了linting错误,那么在将主页加载到浏览器中之前,您不会真正看到这些错误 我实际上能够使用带有的npm包实现lint-on-dev模式
执行此操作时,我的命令看起来像(在package.json
中):
希望这会有帮助