webpack.resolve.plugins中的resolver.resolve和resolver.doResolve有什么区别?

时间:2019-10-02 09:19:04

标签: webpack

我正在尝试使用比平面resolve.alias允许的逻辑更复杂的逻辑来更改导入路径,如果我理解正确,resolve.plugins是放置该逻辑的正确位置。

但是,现在我对几种继续/纾困方法的存在感到困惑,我也不知道该怎么称呼。 resolve seems to call doResolve inside,那么每个对象的实际目的是什么?何时应该调用它们或回调?

  resolve: {
    extensions: ['.mjs', '.ts', '.tsx', '.js', '.jsx'],
    modules: [
      path.join(clientFolder, './src'),
      path.join(clientFolder, './node_modules'),
      'node_modules',
    ],
    plugins: [{
      apply(resolver) {
        resolver.plugin('module', (req, callback) => {
          const { context, path, request } = req
            /* 
              some logic here, maybe change path or filename
            */
            resolver.resolve(/*...*/)
            resolver.doResolve(/*...*/)
            callback(/*..*/)
        })
      }
    }]
  },

0 个答案:

没有答案