英文:
Removing package.json or part of it from app in electron-forge
问题
I have started using electron-forge. My package.json is begin added to the final output after making and packaging.
The package.json contains info which I dont want to to be in production. Such as devDependencies or scripts. Putting package.json in forge.config.js ignore list breaks the build.
Is there a way to remove the file or hide ceratin parts of it in the final packaged app?
英文:
I have started using electron-forge. My package.json is begin added to the final output after making and packaging.
The package.json contains info which I dont want to to be in production. Such as devDependencies or scripts. Putting package.json in forge.config.js ignore list breaks the build.
Is there a way to remove the file or hide ceratin parts of it in the final packaged app?
答案1
得分: 2
使用forge.config.js
文件中的postPackage
钩子,示例代码如下:
{
hooks: {
postPackage: async (forgeConfig, options) => {
console.info('postPackage() Packages built at:', options.outputPaths);
if (!(options.outputPaths instanceof Array)) {
return;
}
const packageDotJson = path.join(options.outputPaths[0], 'resources', 'app', 'package.json');
const content = fs.readFileSync(packageDotJson);
const json = JSON.parse(content.toString());
Object.keys(json).forEach((key) => {
switch (key) {
case 'name': {
break;
}
case 'version': {
break;
}
case 'main': {
break;
}
case 'author': {
break;
}
case 'description': {
break;
}
default: {
delete json[key];
break;
}
}
});
fs.writeFileSync(packageDotJson, JSON.stringify(json, null, '\t'));
},
}
}
英文:
Use the postPackage
hook within your forge.config.js
file, like so for example:
{
hooks: {
postPackage: async (forgeConfig, options) => {
console.info('postPackage() Packages built at:', options.outputPaths);
if (!(options.outputPaths instanceof Array)) {
return;
}
const packageDotJson = path.join(options.outputPaths[0], 'resources', 'app', 'package.json');
const content = fs.readFileSync(packageDotJson);
const json = JSON.parse(content.toString());
Object.keys(json).forEach((key) => {
switch (key) {
case 'name': {
break;
}
case 'version': {
break;
}
case 'main': {
break;
}
case 'author': {
break;
}
case 'description': {
break;
}
default: {
delete json[key];
break;
}
}
});
fs.writeFileSync(packageDotJson, JSON.stringify(json, null, '\t'));
},
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论