Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文档错误,使用的 webpack-chain v4.9.0 对于 module 的 merge 方法的对象参数只支持 rule 属性,不支持 rules 属性 #7357

Closed
Junyan opened this issue Aug 17, 2020 · 1 comment · Fixed by #7369
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@Junyan
Copy link

Junyan commented Aug 17, 2020

相关平台

微信小程序

复现步骤

https://nervjs.github.io/taro/docs/config-detail/#miniwebpackchain

// 根据文档
webpackChain(chain, webpack) {
  chain.merge({
    module: {
      rules: {
        myloader: {
          test: /\.md$/,
          use: [{
            loader: 'raw-loader',
            options: {}
          }]
        }
      }
    }
  })

  console.log(chain.toConfig().module);
}

实际结果

mini.webpackChain 中 module 对象使用 rules 属性,无对 .md 文件处理的 loader 配置

{ rules:
   [ { test: /\.sass$/, oneOf: [Array] },
     { test: /\.scss$/, oneOf: [Array] },
     { test: /\.less$/, oneOf: [Array] },
     { test: /\.styl$/, oneOf: [Array] },
     { test: /\.(css|wxss|acss|ttss)(\?.*)?$/, oneOf: [Array] },
     { test: /\.[tj]sx?$/i, include: [Array], use: [Array] },
     { test: /\.(wxml|axml|ttml|qml|swan|jxml)(\?.*)?$/,
       use: [Array] },
     { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
       use: [Array] },
     { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, use: [Array] },
     { test: /\.(png|jpe?g|gif|bpm|svg|webp)(\?.*)?$/, use: [Array] } ]
}

期望结果

mini.webpackChain 中 module 对象使用 rule 属性

webpackChain(chain, webpack) {
  chain.merge({
    module: {
      // 由 rules 改成 rule
      rule: {
        myloader: {
          test: /\.md$/,
          use: [{
            loader: 'raw-loader',
            options: {}
          }]
        }
      }
    }
  })

  console.log(chain.toConfig().module);
}

有对 .md 文件处理的 loader 配置

{ rules:
   [ { test: /\.sass$/, oneOf: [Array] },
     { test: /\.scss$/, oneOf: [Array] },
     { test: /\.less$/, oneOf: [Array] },
     { test: /\.styl$/, oneOf: [Array] },
     { test: /\.(css|wxss|acss|ttss)(\?.*)?$/, oneOf: [Array] },
     { test: /\.[tj]sx?$/i, include: [Array], use: [Array] },
     { test: /\.(wxml|axml|ttml|qml|swan|jxml)(\?.*)?$/,
       use: [Array] },
     { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
       use: [Array] },
     { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, use: [Array] },
     { test: /\.(png|jpe?g|gif|bpm|svg|webp)(\?.*)?$/, use: [Array] },
     { test: /\.md$/, use: [Array] } ]
}

原因

webpack-chain v4.9.0 文档中 merge 配置可选项:https://www.npmjs.com/package/webpack-chain/v/4.9.0#merging-config
源码:https://github.com/neutrinojs/webpack-chain/blob/v4/src/Config.js

环境信息

👽 Taro v3.0.5


  Taro CLI 3.0.5 environment info:
    System:
      OS: macOS 10.14.4
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
      Yarn: 1.15.2 - ~/.nvm/versions/node/v10.15.3/bin/yarn
      npm: 6.12.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
    npmPackages:
      @tarojs/cli: 3.0.5 => 3.0.5
      @tarojs/components: 3.0.5 => 3.0.5
      @tarojs/taro: 3.0.5 => 3.0.5
      @tarojs/webpack-runner: 3.0.5 => 3.0.5
      eslint-config-taro: 3.0.5 => 3.0.5
      eslint-plugin-taro: 2.1.4 => 2.1.4
      react: ^16.13.1 => 16.13.1
    npmGlobalPackages:
      typescript: 3.5.3
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Aug 17, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 17, 2020

欢迎 PR~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants