From 1a8a4d9b4286bfdc49f7474d37a45a4ca2e41305 Mon Sep 17 00:00:00 2001 From: Noah Klayman Date: Sat, 13 Jun 2020 14:12:03 -0700 Subject: [PATCH] docs: update static assets instructions --- docs/guide/guide.md | 31 ++++++++++++++----------------- docs/guide/security.md | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/guide/guide.md b/docs/guide/guide.md index a02c3b51..567d7fa5 100644 --- a/docs/guide/guide.md +++ b/docs/guide/guide.md @@ -37,36 +37,33 @@ module.exports = { ## Handling Static Assets -### Renderer Process (Vue App) +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. -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: + +:::tip __static +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). +::: -- 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. -- In production, the `process.env.BASE_URL` is replaced with the path to your app's files. - -**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.** - -### Main Process (`background.js`) - -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. +:::warning +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. +::: ### Examples: ```vue - - + - - + - -