要自定义生成electron的package.json
没有现成的webpack插件,需要自己写一个
插件代码
const path = require('path')
const fs = require('fs')
// var packages = require('../../package.json')
class testPlugin {
constructor(options) { // 构造方法
// console.log(options);
}
apply(compiler) {
compiler.plugin('done', function () {
// console.log(compiler.options.output.path);
// console.log(__dirname, __filename, process.cwd())
const oldPackage = require(path.join(process.cwd(), 'package.json'))
// delete oldPackage['build'];
delete oldPackage.devDependencies;
delete oldPackage.scripts;
delete oldPackage.build;
oldPackage.main = './main.js'
// console.log(typeof oldPackage)
fs.writeFile(compiler.options.output.path + '/package.json', JSON.stringify(oldPackage, "", "\t"), (err,
data) => {
if (err) console.log('err')
})
});
}
}
module.exports = testPlugin;
webpack插件简单解释
函数apply(compiler){}必须有,插件自动运行这个函数
(暂时作为记录)
网友评论