mirror of
https://github.com/palxiao/poster-design
synced 2024-11-23 08:38:40 +00:00
25 lines
719 B
JavaScript
25 lines
719 B
JavaScript
const pkg = require("./package.json");
|
|
const fs = require('fs');
|
|
|
|
class MyPlugin {
|
|
apply(compiler) {
|
|
compiler.hooks.emit.tap("BuildPackageJson", (compilation) => {
|
|
console.log("构建 package.json ....");
|
|
const myBuildPackageJson = `{
|
|
name: ${pkg.name+'-builder'},
|
|
version: ${pkg.version},
|
|
dependencies: ${JSON.stringify(pkg.dependencies, null, 2)}
|
|
}`;
|
|
fs.writeFile('./dist/package.json', myBuildPackageJson, 'utf8', (err) => {
|
|
if (err) {
|
|
console.error('保存 package.json 文件时发生错误:', err);
|
|
} else {
|
|
console.log('package.json 文件构建完成!');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = MyPlugin;
|