美文网首页
electron之使用两个package.json

electron之使用两个package.json

作者: 低调的颜某人 | 来源:发表于2020-05-08 09:43 被阅读0次

要自定义生成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){}必须有,插件自动运行这个函数
(暂时作为记录)

相关文章

网友评论

      本文标题:electron之使用两个package.json

      本文链接:https://www.haomeiwen.com/subject/lqyxnhtx.html