账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue-cli3.0 webpack配置exclude报错
    23
    0

    // 配置webpack

    chainWebpack: config => {
        const svgRule = config.module.rule('svg');
    
        svgRule.uses.clear();
    
        config.module
            .rule('svg')
            .set('exclude', [resolve('src/assets/icons')])
            .use('file-loader')
            .loader('file-loader')
            .options({
                name: 'img/[name].[hash:8].[ext]'
            })
            
            

    怎么配置exclude

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 放开那女孩儿 普通会员 1楼

      在Vue CLI 3.0中,Webpack 的配置文件中添加 exclude 属性用于指定排除哪些文件或目录。如果使用 exclude 选项时出现报错,可能的原因如下:

      1. 没有正确地指定 exclude 属性:在Webpack 配置文件中,exclude 属性需要在 <module配置> 标签中指定,例如:

      javascript module.exports = { // ... module: { rules: [ { test: /\.vue$/, exclude: /node_modules/, use: [ // 使用 you-sapper 模块替换 node_modules 目录下的 vue 代码 'your-sapper-loader', ], }, ], }, // ... };

      在上述配置中,/node_modules 是一个包含 node_modules 目录下的所有 vue 文件的路径。如果要排除 node_modules 目录下的所有文件,你需要将这个路径替换为你的实际路径。例如,如果你的 node_modules 目录在 /usr/local/lib 下,你可以将路径修改为:

      javascript module.exports = { // ... module: { rules: [ { test: /\.vue$/, exclude: /node_modules/, use: [ 'your-sapper-loader', ], }, ], }, // ... };

      1. exclude 属性中包含了多个目录:如果你的 exclude 属性包含了多个目录,那么只有最后一个目录被排除在外。在上述配置中,/node_modules 是一个目录,因此只会排除 node_modules 目录下的所有文件。

      2. exclude 选项与 excludePlugin 配置冲突:如果你的 exclude 属性与 excludePlugin 配置冲突,那么 excludePlugin 配置的 includeexclude 选项将覆盖 exclude 属性的值。在 Vue CLI 3.0 中,excludePlugin 配置在 rules 对象的 exclude 属性中,你需要将 exclude 选项设置为 []undefined,以排除所有文件。

      例如,以下配置排除了所有 .vue 文件,但包括了 .vue.js 文件:

      javascript module.exports = { // ... module: { rules: [ { test: /\.vue$/, exclude: /node_modules/, use: [ 'your-sapper-loader', ], }, { test: /\.vue\.js$/, exclude: /node_modules/, use: [ 'your-sapper-loader', ], }, ], }, // ... };

      请确保在你的 Vue CLI 3.0 配置中正确地使用 exclude 属性,并且按照你的需求设置 exclude 选项。如果有任何具体问题,请提供更详细的信息,如你的配置文件、exclude规则、你使用的 Vue CLI 版本等,以便我为您提供更准确的帮助。

    更多回答
    扫一扫访问手机版