mirror of
https://github.com/palxiao/poster-design.git
synced 2025-07-28 04:10:31 +08:00
fix: service/package.json builder
This commit is contained in:
parent
ff134a80db
commit
85594e0210
@ -1,15 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* @Author: ShawnPhang
|
||||||
|
* @Date: 2024-06-19 23:35:21
|
||||||
|
* @Description:
|
||||||
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||||
|
* @LastEditTime: 2024-09-24 19:30:38
|
||||||
|
*/
|
||||||
const pkg = require("./package.json");
|
const pkg = require("./package.json");
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
class MyPlugin {
|
class MyPlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.emit.tap("BuildPackageJson", (compilation) => {
|
compiler.hooks.emit.tap("BuildPackageJson", async (compilation) => {
|
||||||
console.log("构建 package.json ....");
|
console.log("构建 package.json ....");
|
||||||
const myBuildPackageJson = `{
|
const myBuildPackageJson = `{
|
||||||
name: ${pkg.name+'-builder'},
|
name: ${pkg.name+'-builder'},
|
||||||
version: ${pkg.version},
|
version: ${pkg.version},
|
||||||
dependencies: ${JSON.stringify(pkg.dependencies, null, 2)}
|
dependencies: ${JSON.stringify(pkg.dependencies, null, 2)}
|
||||||
}`;
|
}`;
|
||||||
|
await checkCreateFolder('./dist')
|
||||||
fs.writeFile('./dist/package.json', myBuildPackageJson, 'utf8', (err) => {
|
fs.writeFile('./dist/package.json', myBuildPackageJson, 'utf8', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('保存 package.json 文件时发生错误:', err);
|
console.error('保存 package.json 文件时发生错误:', err);
|
||||||
@ -21,4 +29,18 @@ class MyPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测目录并创建目录
|
||||||
|
function checkCreateFolder(folder) {
|
||||||
|
try {
|
||||||
|
const pathArr = splitPath(folder);
|
||||||
|
let _path = "";
|
||||||
|
for (let i = 0; i < pathArr.length; i++) {
|
||||||
|
if (pathArr[i]) {
|
||||||
|
_path += `/${pathArr[i]}`;
|
||||||
|
!fs.existsSync(_path) && fs.mkdirSync(_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = MyPlugin;
|
module.exports = MyPlugin;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user