Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

electron-vue 打包异常,未能打包成功

问题描述

基础信息:
平台:MacOS
cli:electron-vue
打包工具:electron-builder

问题:在使用electron-builder打包的时候,运行命令:sudo yarn run build:dir,报错,如图
image.png

问题出现的环境背景及自己尝试过哪些方法

尝试清空了node_modules文件夹,用npm重新安装依赖,打包报错;
再清空node_modules文件夹,用yarn重新安装依赖,打包报错

相关代码

package.json

"scripts": {
    "build": "node .electron-vue/build.js && electron-builder",
    "build:dir": "node .electron-vue/build.js && electron-builder --dir",
    "build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
    "build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
    "build:mac": "node .electron-vue/build.js && electron-builder --platform=darwin",
    "dev": "node .electron-vue/dev-runner.js",
    "lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src",
    "lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src",
    "pack": "npm run pack:main && npm run pack:renderer",
    "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
    "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
    "postinstall": "npm run lint:fix"
  },

你期待的结果是什么?实际看到的错误信息又是什么?

希望可以打包成功


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

解决方案
两处修改:
1、在.electron-vue/webpack.renderer.config.js 文件找到CopyWebpackPlugin,大概在186行左右,

new CopyWebpackPlugin([
      {
        from: path.join(__dirname, '../static'),
        to: path.join(__dirname, '../dist/electron/static'),
        ignore: ['.*']
      }
    ]),

改为

new CopyWebpackPlugin({
      patterns: [{
        from: path.join(__dirname, '../static'),
        to: path.join(__dirname, '../dist/electron/static')
      }]
    })

2、在.electron-vue/webpack.web.config.js 文件找到CopyWebpackPlugin,大概在135行左右,

new CopyWebpackPlugin([
      {
        from: path.join(__dirname, '../static'),
        to: path.join(__dirname, '../dist/web/static')
        ignore: ['.*']
      }
    ]),

改为

new CopyWebpackPlugin({
      patterns: [{
        from: path.join(__dirname, '../static'),
        to: path.join(__dirname, '../dist/web/static')
      }]
    })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
...