关于 electron-vue打包后静态资源路径失效的解决方案

1.静态资源如css,img,js,请放在根目录的static文件夹里,
因为electron打包后会复制一份static文件夹到dist文件夹中
这样项目引入的静态资源就不会报路径错误了。

2.字体文件比较特殊,如果引入的是前端框架文件,引入的字体 路径不是我们能控制的。所以我们需要修改下C:\Users\sendi\Desktop\ele-vue1.electron-vue \webpack.renderer.config.js文件

3.找到该文件中代码片段
if (process.env.NODE_ENV === ‘production’) {
rendererConfig.devtool = ”

  rendererConfig.plugins.push(
    new BabiliWebpackPlugin(),
    new CopyWebpackPlugin([
      {
        from: path.join(__dirname, '../static'),//需要复制的文件路径
        to: path.join(__dirname, '../dist/electron/static'),//复制到哪里
        ignore: ['.*']//复制的文件类型
      },
      {
        //这是新添加的数组,把对应的字体路径复制到正确路径中就OK了
        from:path.join(__dirname,'../fonts'),
        to:path.join(__dirname,'../dist/electron/fonts'),
        ignore:['.*']
      }
    ]),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': '"production"'
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  )
}
Logo

前往低代码交流专区

更多推荐