1.compiler

// Compiler.seal executes a callback after the resource is generated
// Take charge of building resource output
this.emitAssets(compilation, err= > {})
// Execute the callback again
this.hooks.afterEmit.callAsync(compilation, (err) = > {
  return callback();
})
/ / emitRecords execution
this.emitRecords()
Copy the code

2.emitAssets

// The core is to iterate over assets by calling fs.writefile
function emitAssets(compilation, callback) {
  // neo-async executes in parallel
  asyncLib.forEachLimit(
    compilation.getAssets(),
    15.({ name: file, source }, callback) = > {
      const writeOut = (err) = > {
        // Real path
        const targetPath = this.outputFileSystem.join(outputPath, targetFile);
        let content = source.source();
        if(! Buffer.isBuffer(content)) { content = Buffer.from(content,"utf8"); / / use the buffer
        }
        // fs.writeFile
        this.outputFileSystem.writeFile(targetPath, content, (err) = > {
          this.hooks.assetEmitted.callAsync(file, content, callback);
        });
      };
      // Create directories and output resources recursively
      this.outputFileSystem.mkdirp(
        this.outputFileSystem.join(outputPath, dir),
        writeOut
      );
    },
    (err) = > {
      returncallback(); }); }Copy the code

3.emitRecords

// Set stats to run callback parameters
Copy the code