Electron-vue: Path for static assets in production build (dev branch)

Created on 27 Apr 2017  Â·  3Comments  Â·  Source: SimulatedGREG/electron-vue

Found an issue or bug? Tell me all about!

I'm having problems referencing static assets, I'm using the dev branch.

Describe the issue / bug.

Webpack says:

webpack output is served from /
Content not from webpack is served from /Users/oriol/project/dist/static

Therefore, I placed an .svg file accordingly:

dist/
\- static/
    \- assets/
        \- file.svg

In my .vue component, the file is referenced as:
``` pug syntax
object(type="image/svg+xml" data="./assets/file.svg")


During development, the file displays properly. However, once I build (`npm run build:darwin`), it is not displayed.

I don't think this is a bug but a question, since most probably I'm doing something wrong. I read the [docs](https://simulatedgreg.gitbooks.io/electron-vue/content/en/renderer-process.html#using-static-assets) on this topic but I can't get it clear.
If I use the root of `dist`:
``` pug syntax
object(type="image/svg+xml" data="./static/assets/file.svg")

It doesn't work in development, neither in production.
What I'm doing wrong Greg? Thank you!

Note: first I tried to place it inside src/renderer/... as in the sample Landing page, but didn't show up in development neither.

How can I reproduce this problem?

Clean install using the dev branch using the directory structure and code described above.

Tell me about your development environment.
  • Node version: 6.9.5
  • NPM version: 3.10.10
  • vue-cli version: (if necessary)
  • Operating System: MacOS Sierra
bug

Most helpful comment

I may be doing something wrong, but when I npm run build my static files don't seem to get included with my app.

Any ideas?

All 3 comments

@Oriol-GG

This is actually a bug that I never seemed to have noticed. Added in the copy-webpack-plugin to handle this. There will be a new static folder in the project root (similar to how vuejs-templates/webpack handles this). The fix is currently in the dev branch and will be published in the next milestone, #171 for more info.

Example

static/
  - my-image.jpg

SomeComponent.vue

<img src="static/my-image.jpg">

Thank you @SimulatedGREG!

I just made a new project from dev to test it out.
In the landing page component, I changed the img element, to be in the statics folder instead following your example. And I also added an svg file:

<img src="static/logo.png" alt="electron-vue">
<object type="image/svg+xml" data="static/my-vector.svg"></object>

And then place them in static:

static/
  - logo.png
  - my-vector.svg

Results:
🔴 Development: neither of both files appear. Error says it cannot GET the files.
✅ Build: both assets are properly included in the production app.

Conclusion: the fix works for production, but seems to be some issue related to webpack in development.

^ Edit: I found the issue, CopyWebpackPlugin was referenced only in Production config. I fixed it in PR here: #211

Thanks for your help!

I may be doing something wrong, but when I npm run build my static files don't seem to get included with my app.

Any ideas?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pansila picture pansila  Â·  3Comments

mvalim picture mvalim  Â·  4Comments

rodrigomata picture rodrigomata  Â·  3Comments

michalzaq12 picture michalzaq12  Â·  3Comments

simonwjackson picture simonwjackson  Â·  3Comments