我曾经使用elctron-vue
=> electron5 + webpack
现在我已将其升级到vue-cli4 + elctron8
,我有问题!
这里是错误:
Building modern bundle for production...(node:11124) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'D:\xxx\electron-vue-demo\dist_electron\bundled\legacy-assets-index.json'
我可以成功执行本地调试,但是构建器失败。
legacy-assets-index.json
我查了一下,似乎是自动生成。
我已经检查了下面cli4的文档,但没有找到原因。
这里是我的vue.config.js
let path = require('path')
let glob = require('glob') // 用于筛选文件
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin');
function resolve(dir) {
return path.join(__dirname, dir)
}
// 工厂函数 - 配置pages实现多页面获取某文件夹下的html与js
function handleEntry(entry) {
let entries = {}
let entryBaseName = ''
let entryPathName = ''
let entryTemplate = ''
glob.sync(entry).forEach(item => {
console.log('!!!', item)
entryTemplate = item.split('/').slice(0, 5)
console.log('entryTemplate:', entryTemplate)
entryBaseName = entryTemplate[4]
console.log('entryBaseName:', entryBaseName)
entryPathName = entryBaseName // 正确输出js和html的路径
console.log('entryPathName', entryPathName)
entries[entryPathName] = {
app: `.\\` + path.join(...entryTemplate, 'main.js'),
entry: `.\\` + path.join(...entryTemplate, 'main.js'),
template: `.\\` + path.join(...entryTemplate, 'public', 'index.html'),
// title: entryPathName,
filename: entryPathName
}
})
return entries
}
let pages = handleEntry('./src/renderer/pages/**?/public/index.html')
let WebpackRenderer = config => {
config.plugin('define').use(webpack.DefinePlugin, [{
'process.env': {
NODE_ENV: '"production"',
BASE_URL: '`require("electron").remote.app.getAppPath()`',
IS_ELECTRON: true
},
__dirname: '`require("electron").remote.app.getAppPath()`',
__filename: '`${require("electron").remote.app.getAppPath()}/index.html`',
__static: '`require("electron").remote.app.getAppPath()`'
}])
config.entryPoints.clear() // 会把默认的入口清空
Object.keys(pages).forEach(entryName => {
// config.plugin('html').use(HtmlWebpackPlugin, [pages[entryName]])
config.plugin(`html-${entryName}`).use(HtmlWebpackPlugin, [pages[entryName]])
config.entry(entryName).add( pages[entryName].entry)
})
console.log(config.toString())
}
module.exports = {
configureWebpack: {
// Configuration applied to all builds
},
pluginOptions: {
electronBuilder: {
chainWebpackMainProcess: config => {
// Chain webpack config for electron main process only
},
chainWebpackRendererProcess: WebpackRenderer,
// Use this to change the entrypoint of your app's main process
mainProcessFile: 'src/electron/main.js',
// Provide an array of files that, when changed, will recompile the main process and restart Electron
// Your main process file will be added by default
// mainProcessWatch: ['src/myFile1', 'src/myFile2'],
// [1.0.0-rc.4+] Provide a list of arguments that Electron will be launched with during "electron:serve",
// which can be accessed from the main process (src/background.js).
// Note that it is ignored when --debug flag is used with "electron:serve", as you must launch Electron yourself
// Command line args (excluding --debug, --dashboard, and --headless) are passed to Electron as well
mainProcessArgs: ['--arg-name', 'arg-value']
},
}
}
我的英语不是很好,如果您不明白这个问题,我可以继续填写详细信息
我有一个类似的问题,问题是vue.config.js
中有一些选项,导致Vue使用错误的构建目录。我删除了所有不必要的选项,现在可以使用了。尝试删除所有选项,然后再次添加它们,直到其停止工作。特别是这行似乎没用:
mainProcessArgs: ['--arg-name', 'arg-value']