nuxt 项目设置缩进为4个空格

1、.editorconfig 文件下的indent_size: 2更改为indent_size: 4
2、.prettierrc 文件

{
    "singleQuote": true, // 使用单引号 `.vscode/settings.json` 的`prettier.semi`
    "semi": false, // 结尾不加分号 `.vscode/settings.json` 的`prettier.semi`
    "printWidth": 120 // 此项为我自加以上两项为默认,表示每行最多显示的字符数,默认为80,本人觉得太短了,因此修改了一下,必须与`.vscode/settings.json` 的`prettier.printWidth`对应上
/* 更多配置请戳 https://prettier.io/docs/en/options.html */
}

3、.eslintrc.js 文件配置

module.exports = {
    root: true,
    env: {
        browser: true,
        node: true
    },
    parserOptions: {
        parser: 'babel-eslint'
    },
    extends: [
        '@nuxtjs',
        'plugin:nuxt/recommended',
        'plugin:prettier/recommended',
        'prettier',
        'prettier/vue'
    ],
    plugins: ['prettier'],
    // add your custom rules here
    rules: {
        'nuxt/no-cjs-in-config': 'off',
        indent: ['error', 4] // 4个空格缩进
        /* 更多配置请戳 http://eslint.cn/docs/rules/ */
    }
}

4、nuxt.config.js文件下build.extend(config, ctx) {}添加options.fix: true

    build: {
        /*
         ** You can extend webpack config here
         */
        extend(config, ctx) {
            // Run ESLint on save
            if (ctx.isDev && ctx.isClient) {
                config.module.rules.push({
                    enforce: 'pre',
                    test: /.(js|vue)$/,
                    loader: 'eslint-loader',
                    exclude: /(node_modules)/,
                    options: {
                        fix: true
                    }
                })
            }
        }
    }
原文地址:https://www.cnblogs.com/cag2050/p/11169148.html