rsnext/packages/next/taskfile-webpack.js
Jimmy Lai 5217e7eb06
server: re-land bundled runtimes (#55139)
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>
2023-09-08 16:05:29 +00:00

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()
})
})
}
})
}