vue-cli-plugin-electron-builder icon indicating copy to clipboard operation
vue-cli-plugin-electron-builder copied to clipboard

__static (realDirname) is not right in build when asar is disabled

Open asakiasako opened this issue 3 years ago • 1 comments

Version info:

  • vue-cli-plugin-electron-builder: 2.0.0
  • electron: 12.0.0

Platform:

  • windows 10

I used fs.readFileSync() to load a file in __static folder in renderer process. The file opened normally in dev but could not be found after build.

fs.readFileSync(path.join(__static, 'CHANGELOG.md'))

I think it's a issue about vue-cli-plugin-electron-builder/lib/webpackConfig.js /

Since I disabled asar (set { asar: false } in electron-builder config), the __static const should point to folder /app instead of /app.asar. The folder name is different if asar is disabled.

In file webpackConfig.js, line 9 to 14, if I mod app.asar into app, the file could be opened normally in build env.

  const realDirname = semver.gte(
    ((devDependencies || {}).electron || '12.0.0').replace(/^\^/, ''),
    '12.0.0'
  )
-    ? '__dirname.replace(/electron\\.asar(\\\\|\\/)renderer/, "app.asar")'
+    ? '__dirname.replace(/electron\\.asar(\\\\|\\/)renderer/, "app")'
    : 'require("electron").remote.app.getAppPath()'

So I think the __static const (i.e. realDirname) did not consider the case when asar is disabbled.

I understand disabling asar is not suggested, but I still hope to fix this, since sometimes disabling asar is a quick way to avoid some issues.

asakiasako avatar Jun 29 '21 15:06 asakiasako

meet the same situation

KotoriMinami avatar Oct 09 '21 06:10 KotoriMinami