This is a Vue application using electron-builder.
{
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
},
"main": "background.js",
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-property-decorator": "^8.4.2",
"vue-router": "^3.3.2",
"vuetify": "^2.2.33"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-plugin-eslint": "~4.4.0",
"@vue/cli-plugin-router": "~4.4.0",
"@vue/cli-plugin-typescript": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"electron": "^6.1.12",
"typescript": "^3.9.5",
"vue-cli-plugin-electron-builder": "~1.4.6",
"vue-cli-plugin-vuetify": "~2.0.5",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.3.0"
}
}
When running npm run electron:build
, the structure generated looks like this:
https://i.stack.imgur.com/N5rL7.png
The contents of app.asar can be viewed here:
https://i.stack.imgur.com/IcDFz.png
The background.js file includes all the dependencies. However, there are external modules (from node_modules) that read files using fs.readFile(__dirpath + '/file')
. Since these files are not included in the generated bundle, they need to be added manually.
An attempt was made to include these files in vue.config.js:
module.exports = {
lintOnSave: true,
transpileDependencies: [
'vuetify'
],
configureWebpack: {
devtool: 'source-map'
},
pluginOptions: {
electronBuilder: {
builderOptions: {
extraFiles: [
'node_modules/module/file'
]
}
}
}
}
However, the file is still placed outside the app.asar, even with the use of extraResources
. As a result, fs.readFile(__dirpath + '/file')
cannot locate the file.
How can I successfully include files inside app.asar?