Skip to content

Commit

Permalink
Merge pull request #1398 from didi/fix-webpack-outputfilesystem-write…
Browse files Browse the repository at this point in the history
…file

fix: 重写compiler.outputFileSystem.writeFile方法时适配其可选参数
  • Loading branch information
hiyuki authored Jan 31, 2024
2 parents 10b9dfb + cce4fac commit db51bdd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,18 @@ class MpxWebpackPlugin {
if (this.options.writeMode === 'changed') {
const writedFileContentMap = new Map()
const originalWriteFile = compiler.outputFileSystem.writeFile
compiler.outputFileSystem.writeFile = (filePath, content, callback) => {
// fs.writeFile(file, data[, options], callback)
compiler.outputFileSystem.writeFile = (filePath, content, ...args) => {
const lastContent = writedFileContentMap.get(filePath)
if (Buffer.isBuffer(lastContent) ? lastContent.equals(content) : lastContent === content) {
return callback()
const callback = args[args.length - 1]
if (typeof callback === 'function') {
callback()
}
return
}
writedFileContentMap.set(filePath, content)
originalWriteFile(filePath, content, callback)
originalWriteFile(filePath, content, ...args)
}
}

Expand Down

0 comments on commit db51bdd

Please sign in to comment.