You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/guide.md
+14-17Lines changed: 14 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -37,36 +37,33 @@ module.exports = {
37
37
38
38
## Handling Static Assets
39
39
40
-
### Renderer Process (Vue App)
40
+
Static assets work the same as a regular web app. Read Vue CLI's documentation [here](https://cli.vuejs.org/guide/html-and-static-assets.html#static-assets-handling) for more information.
41
41
42
-
In the renderer process, static assets work similarly to a regular app. Read Vue CLI's documentation [here](https://cli.vuejs.org/guide/html-and-static-assets.html) before continuing. However, there are a few changes made:
42
+
<!-- prettier-ignore -->
43
+
:::tip __static
44
+
Available only in Electron, the global variable `__static` is added to the main and renderer process. It is set to the path of your public folder on disk. This is useful if you need to use Node APIs on the file, such as`fs.readFileSync`or`child_process.spawn`. Note that files in the public folder are read-only in production as they are packaged into a `.asar` archive. If you need files to be writeable, use [electron-builder's extraResources config](https://www.electron.build/configuration/contents#extraresources).
45
+
:::
43
46
44
-
- The `__static` global variable is added. It provides a path to your public directory in both development and production. Use this to read/write files in your app's public directory.
45
-
- In production, the `process.env.BASE_URL` is replaced with the path to your app's files.
46
-
47
-
**Note: `__static` is not available in regular build/serve. It should only be used in electron to read/write files on disk. To import a file (img, script, etc...) and not have it be transpiled by webpack, use the `process.env.BASE_URL` instead.**
48
-
49
-
### Main Process (`background.js`)
50
-
51
-
The main process won't have access to `process.env.BASE_URL` or `src/assets`. However, you can still use `__static` to get a path to your public directory in development and production.
47
+
:::warning
48
+
Sourcing images from the `public` folder will fail on v2.0 beta and rc.1. Please upgrade to v2.0.0-rc.2 for a fix.
49
+
:::
52
50
53
51
### Examples:
54
52
55
53
```vue
56
-
<!-- Renderer process only -->
57
-
<!-- This image will be processed by webpack and placed under img/ -->
54
+
<!-- To load an image that will be processed by webpack -->
58
55
<img src="./assets/logo.png">
59
-
<!-- Renderer process only -->
60
-
<!-- This image will no be processed by webpack, just copied-->
56
+
<!-- To load an image from the `public` folder which webpack will not process, just copy -->
61
57
<!-- imgPath should equal `path.join(process.env.BASE_URL, 'logo.png')` -->
62
58
<img :src="imgPath">
63
-
<!-- Both renderer and main process -->
64
-
<!-- This will read the contents of public/myText.txt -->
65
59
<script>
60
+
// Only works in electron serve/build
61
+
// Will not work in renderer process unless you enable nodeIntegration
62
+
// Expects myText.txt to be placed in public folder
63
+
66
64
const fs = require('fs')
67
65
const path = require('path')
68
66
69
-
// Expects myText.txt to be placed in public folder
Copy file name to clipboardExpand all lines: docs/guide/security.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Now, you can access `ipcRenderer` with `window.ipcRenderer` in your Vue app.
29
29
30
30
## Loading Local Images/Resources
31
31
32
-
If WebSecurity is enabled, you won't be able to load resources from the file system, ie `<img src="file://image.png"/>`. [Disabling WebSecurity is strongly discouraged](https://www.electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity), so you should instead use the following technique to load local resources and keep WebSecurity enabled.
32
+
If WebSecurity is enabled, you won't be able to load resources from the file system, ie `<img src="file:///path/to/some/image.png"/>`. However, you will still be able to load images and other resources from the `public` folder, see [handling static assets](./guide.html#handling-static-assets). If you need to load resources from outside of the public folder you will have to disable WebSecurity or use a custom protocol. [Disabling WebSecurity is strongly discouraged](https://www.electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity), so you should instead use the following technique to load local resources and keep WebSecurity enabled.
33
33
34
34
Add the following to your main process file (`background.(js|ts)` by default):
0 commit comments