Nuxt3 中使用 ESLint
warning:
这篇文章距离上次修改已过192天,其中的内容可能已经有所变动。
// nuxt.config.js
export default defineNuxtConfig({
// 其他配置...
build: {
// 配置 ESLint
extend(config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/,
options: {
// ESLint 配置文件的路径
configFile: './.eslintrc-nuxt.cjs',
// 自动修复某些问题
fix: true,
},
});
}
},
},
// 其他配置...
});
在这个配置中,我们使用了Nuxt3的defineNuxtConfig
函数来导出配置。在build.extend
函数中,我们添加了一个新的规则,这个规则使用eslint-loader
来在构建客户端代码时进行预处理,并且在开发环境中生效。我们指定了要排除的node_modules
目录,并且通过configFile
指定了ESLint的配置文件路径。这样,在开发过程中,每当代码被编译时,ESLint 都会运行,检查代码质量并可能自动修复一些问题。
评论已关闭