Skip to content

Commit bf037cf

Browse files
committed
update README to include instructions for handling static assets
1 parent 20a5e98 commit bf037cf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,27 @@ module.exports = {
9898
}
9999
};
100100
```
101+
### 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+
104+
- 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.
105+
- In production, the `process.env.BASE_URL` is replaced with the path to your app's files.
106+
107+
**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.**
108+
#### Examples:
109+
```html
110+
<!-- This image will be processed by webpack and placed under img/ -->
111+
<img src="./assets/logo.png">
112+
<!-- This image will no be processed by webpack, just copied-->
113+
<!-- imgPath should equal `path.join(process.env.BASE_URL, 'logo.png')` -->
114+
<img :src="imgPath">
115+
<!-- This will read the contents of public/myText.txt -->
116+
<script>
117+
const fs = require('fs')
118+
const path = require('path')
119+
console.log(fs.readFileSync(path.join(__static, 'myText.txt'), 'utf8'))
120+
</script>
121+
```
101122

102123
### Changing the output directory:
103124
If you don't want your files outputted into dist_electron, you can choose a custom folder in vue-cli-plugin-electron-builder's plugin options.

0 commit comments

Comments
 (0)