5217e7eb06
see https://github.com/vercel/next.js/pull/52997 also added a fix by @jridgewell to fix turbopack Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
35 lines
984 B
JavaScript
35 lines
984 B
JavaScript
const webpack = require('webpack')
|
|
|
|
module.exports = function (task) {
|
|
task.plugin('webpack', {}, function* (_, options) {
|
|
options = options || {}
|
|
|
|
const compiler = webpack(options.config)
|
|
|
|
if (options.watch) {
|
|
compiler.watch({}, (err, stats) => {
|
|
if (err || stats.hasErrors()) {
|
|
console.error(err || stats.toString())
|
|
} else {
|
|
console.log(`${options.name} compiled successfully.`)
|
|
}
|
|
})
|
|
} else {
|
|
yield new Promise((resolve, reject) => {
|
|
compiler.run((err, stats) => {
|
|
if (err || stats.hasErrors()) {
|
|
console.error(err || stats.toString())
|
|
reject(err || stats.toString())
|
|
}
|
|
if (process.env.ANALYZE) {
|
|
require('fs').writeFileSync(
|
|
require('path').join(__dirname, options.name + '-stats.json'),
|
|
JSON.stringify(stats.toJson())
|
|
)
|
|
}
|
|
resolve()
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|