babel 语法检查 eslint-loader

博客探讨了在Webpack配置中,为何要确保eslint-loader在babel-loader之前加载,以此确保代码语法的正确性。通过使用eslint-loader,可以利用eslint对代码进行详细的语法检查。更多关于eslint的信息可在eslint官方文档中查找。

eslint-loader应该加载在babel-loader之前
该模块会检查我们的代码语法是否正确
如下webpack的配置

module: {
    rules: [
        {
            test: /\.(js|mjs|jsx|ts|tsx)$/,
            enforce: 'pre',
            use: [
                {
                    options: {
                        cache: true,
                        formatter: require.resolve('react-dev-utils/eslintFormatter'),
                        eslintPath: require.resolve('eslint'),
                        resolvePluginsRelativeTo: __dirname,

                    },
                    loader: require.resolve('eslint-loader'),
                },
            ],
            include: paths.appSrc,
        },
        {
            test: /\.(js|jsx)$/,
            exclude: [/node_modules/],
            use: {
                loader: 'babel-loader',
                options: {
                    sourceMap: true,
                    plugins: [
                        "add-module-exports",
                        ['import', { libraryName: "antd", style: 'css' }]
                    ]
                }
            }
        }]
}

该模块使用eslint模块进行语法检查,更多详情参见eslint

C:\Users\liuchaokun>npm list eslint-plugin-vue liuchaokun@ C:\Users\liuchaokun `-- eslint-plugin-vue@6.0.0 PS D:\My JAVA\苍穹外卖\前端源码\苍穹外卖前端源码\project-sky-admin-vue-ts> npm install npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @typescript-eslint/eslint-plugin@1.13.0 npm WARN Found: eslint@6.7.2 npm WARN node_modules/eslint npm WARN dev eslint@"^6.2.2" from the root project npm WARN 10 more (@typescript-eslint/experimental-utils, babel-eslint, ...) npm WARN npm WARN Could not resolve dependency: npm WARN peer eslint@"^5.0.0" from @typescript-eslint/eslint-plugin@1.13.0 npm WARN node_modules/@typescript-eslint/eslint-plugin npm WARN @typescript-eslint/eslint-plugin@"^1.1.0" from @vue/eslint-config-typescript@4.0.0 npm WARN node_modules/@vue/eslint-config-typescript npm WARN npm WARN Conflicting peer dependency: eslint@5.16.0 npm WARN node_modules/eslint npm WARN peer eslint@"^5.0.0" from @typescript-eslint/eslint-plugin@1.13.0 npm WARN node_modules/@typescript-eslint/eslint-plugin npm WARN @typescript-eslint/eslint-plugin@"^1.1.0" from @vue/eslint-config-typescript@4.0.0 npm WARN node_modules/@vue/eslint-config-typescript npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @typescript-eslint/parser@1.13.0 npm WARN Found: eslint@6.7.2 npm WARN node_modules/eslint npm WARN dev eslint@"^6.2.2" from the root project npm WARN 10 more (@typescript-eslint/experimental-utils, babel-eslint, ...) npm WARN npm WARN Could not resolve dependency: npm WARN peer eslint@"^5.0.0" from @typescript-eslint/parser@1.13.0 npm WARN node_modules/@typescript-eslint/parser npm WARN peer @typescript-eslint/parser@"^1.9.0" from @typescript-eslint/eslint-plugin@1.13.0 npm WARN node_modules/@typescript-eslint/eslint-plugin npm WARN 1 more (@vue/eslint-config-typescript) npm WARN npm WARN Conflicting peer dependency: eslint@5.16.0 npm WARN node_modules/eslint npm WARN peer eslint@"^5.0.0" from @typescript-eslint/parser@1.13.0 npm WARN node_modules/@typescript-eslint/parser npm WARN peer @typescript-eslint/parser@"^1.9.0" from @typescript-eslint/eslint-plugin@1.13.0 npm WARN node_modules/@typescript-eslint/eslint-plugin npm WARN 1 more (@vue/eslint-config-typescript) npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: eslint-plugin-vue@5.2.3 npm ERR! Found: eslint@6.7.2 npm ERR! node_modules/eslint npm ERR! dev eslint@"^6.2.2" from the root project npm ERR! peer eslint@"*" from @typescript-eslint/experimental-utils@1.13.0 npm ERR! node_modules/@typescript-eslint/experimental-utils npm ERR! @typescript-eslint/experimental-utils@"1.13.0" from @typescript-eslint/eslint-plugin@1.13.0 npm ERR! node_modules/@typescript-eslint/eslint-plugin npm ERR! @typescript-eslint/eslint-plugin@"^1.1.0" from @vue/eslint-config-typescript@4.0.0 npm ERR! node_modules/@vue/eslint-config-typescript npm ERR! dev @vue/eslint-config-typescript@"^4.0.0" from the root project npm ERR! @typescript-eslint/experimental-utils@"1.13.0" from @typescript-eslint/parser@1.13.0 npm ERR! node_modules/@typescript-eslint/parser npm ERR! peer @typescript-eslint/parser@"^1.9.0" from @typescript-eslint/eslint-plugin@1.13.0 npm ERR! node_modules/@typescript-eslint/eslint-plugin npm ERR! @typescript-eslint/eslint-plugin@"^1.1.0" from @vue/eslint-config-typescript@4.0.0 npm ERR! node_modules/@vue/eslint-config-typescript npm ERR! 1 more (@vue/eslint-config-typescript) npm ERR! 9 more (babel-eslint, eslint-config-standard, eslint-loader, ...) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer eslint@"^5.0.0" from eslint-plugin-vue@5.2.3 npm ERR! node_modules/eslint-plugin-vue npm ERR! dev eslint-plugin-vue@"^5.2.3" from the root project npm ERR! npm ERR! Conflicting peer dependency: eslint@5.16.0 npm ERR! node_modules/eslint npm ERR! peer eslint@"^5.0.0" from eslint-plugin-vue@5.2.3 npm ERR! node_modules/eslint-plugin-vue npm ERR! dev eslint-plugin-vue@"^5.2.3" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See C:\Users\liuchaokun\AppData\Local\npm-cache\eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\liuchaokun\AppData\Local\npm-cache\_logs\2025-07-27T16_34_12_941Z-debug-0.log
07-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值