错误代码
[DEP0128] DeprecationWarning: Invalid 'main' field in 'D:\Vue\some\dist_electron\package.json' of 'background.js'. Please either fix that or report it to the module author
官方解释
Modules that have an invalid main entry (e.g., ./does-not-exist.js) and also have an index.js file in the top level directory will resolve the index.js file. That is deprecated and is going to throw an error in future Node.js versions.
具有无效主条目(例如,./does-not-exist.js)并且在顶级目录中还有 index.js 文件的模块将解析 index.js 文件。这已被弃用,并将在未来的 Node.js 版本中引发错误。
白话说就是同级目录有index.js文件存在,需要更改electron主进程文件名。 在开发过程中,dist_electron目录会生成两个文件:index.js和package.json,冲突就在这个文件夹。 只需要把index.js文件名修改成background.js就可以了。
build过程反倒是没有警告出现。
解决方案 修改vue.config.js文件
pluginOptions: {
electronBuilder: {
chainWebpackMainProcess: (config) => {
config.output.filename((file) => {
if (file.chunk.name === 'index') {
return 'background.js';
} else {
return '[name].js';
}
});
}
}
}
原理说明
修改vue-cli-plugin-electron-builder插件默认输入文件名