Skip to content

Commit 080dae3

Browse files
committed
update README
1 parent 2a1967a commit 080dae3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ or with NPM:
4848
│ ├── [application name] setup [version].[target binary (exe|dmg|rpm...)] # installer for Electron app
4949
│ ├── background.js # compiled background file used for serve:electron
5050
│ └── ...
51+
├── public/ # Files placed here will be avalible through __static or process.env.BASE_URL
5152
├── src/
5253
│ ├── background.[js|ts] # electron entry file (for Electron's main process)
5354
│ ├── [main|index].[js|ts] # your app's entry file (for Electron's render process)
@@ -99,24 +100,35 @@ module.exports = {
99100
};
100101
```
101102
### Handling static assets:
102-
Static assets work similarily to a regular app. Read Vue CLI's documentation [here](https://cli.vuejs.org/guide/html-and-static-assets.html). However, there are a few changes made:
103+
#### Renderer process (main app):
104+
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:
103105

104106
- 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.
105107
- In production, the `process.env.BASE_URL` is replaced with the path to your app's files.
106108

107109
**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.**
110+
#### Main process (background.js):
111+
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.
108112
#### Examples:
109113
```html
114+
<!-- Renderer process only -->
110115
<!-- This image will be processed by webpack and placed under img/ -->
111116
<img src="./assets/logo.png">
117+
<!-- Renderer process only -->
112118
<!-- This image will no be processed by webpack, just copied-->
113119
<!-- imgPath should equal `path.join(process.env.BASE_URL, 'logo.png')` -->
114120
<img :src="imgPath">
121+
<!-- Both renderer and main process -->
115122
<!-- This will read the contents of public/myText.txt -->
116123
<script>
117124
const fs = require('fs')
118125
const path = require('path')
119-
console.log(fs.readFileSync(path.join(__static, 'myText.txt'), 'utf8'))
126+
127+
// Expects myText.txt to be placed in public folder
128+
const fileLocation = path.join(__static, 'myText.txt')
129+
const fileContents = fs.readFileSync(fileLocation, 'utf8')
130+
131+
console.log(fileContents)
120132
</script>
121133
```
122134

0 commit comments

Comments
 (0)