Webpack 之 buildModule

161 阅读1分钟
  1. addEntry

  2. addModule

  3. buildModule

buildModule(module, callback) {
    this.buildQueue.add(module, callback);
}
this.buildQueue = new AsyncQueue({
	name: "build",
	parent: this.factorizeQueue,
	processor: this._buildModule.bind(this)
});
  1. _buildModule

  2. 调用子module的build方法

  • 如果是JS文件,则调用webpack/lib/NormalModule.js中的build方法
  • 如果是css文件,且配置了css-minimizer-webpack-plugin插件作为编译器,则调用该插件的build方法。

css-minimizer-webpack-plugin插件的build方法

    build(options, compilation, resolver, fileSystem, callback) {
        this.buildInfo = {
          assets: this.assets,
          assetsInfo: this.assetsInfo,
          cacheable: true,
          hash: this._computeHash(compilation.outputOptions.hashFunction)
        };
        this.buildMeta = {};
        this._needBuild = false;
        callback();
      }
  1. build方法中会计算文件hash