Giter VIP home page Giter VIP logo

Comments (6)

Deluze avatar Deluze commented on May 15, 2024 2

You made me think of a potentially better solution @immafrady 👍

We could check if the change happened to one of the static files. Copy only and only the static file that got changed & restart Electron after. When a change has been made outside of the static files, we don't have to copy anything explicitly.

Update: Already implemented now in 4f3d845

from electron-vue-template.

Deluze avatar Deluze commented on May 15, 2024 1

This is unintended.

The following line of code is being fired when you spin up the dev server:

FileSystem.cpSync(
  Path.join(__dirname, '..', 'src', 'main', 'static'), 
  Path.join(__dirname, '..', 'build', 'main', 'static'), 
  { recursive: true }
);

The electron-builder config is ignored when you work in a dev environment, electron-builder config is only used when you actually build the application for production / distributing. I didn't encounter an issue with static files, I'm also on W11/MacOS. So your PR (#18) is incorrect, following the README on how static files should work.

A little side note that is missing from the README is that static files are only copied over ONCE after running npm run dev, if you added new files to the static directory you will need to restart your dev server. This is to prevent copying over static (potentionally big) files after every change.

I'll close this issue & PR with the assumption of that you didn't restart your dev server. If that's not the case and there's actually another issue going on please re-open this 😄 I'll also extend the readme with more details about this behavior.

from electron-vue-template.

zhanglongqi avatar zhanglongqi commented on May 15, 2024

Thanks for your clarification. Now I know it's because I develop the application on mac and package on windows, I run npm run build directly instead of running npm run dev, that's why the static files are never being copied.

from electron-vue-template.

zhanglongqi avatar zhanglongqi commented on May 15, 2024

For the PR #18, actually we do not need

 {
      "from": "src/main/static",
      "to": "static",
      "filter": ["**/*"]
},

because the "build/main/**/*", already cover all of the main static files already .

image

from electron-vue-template.

immafrady avatar immafrady commented on May 15, 2024

A little side note that is missing from the README is that static files are only copied over ONCE after running npm run dev, if you added new files to the static directory you will need to restart your dev server. This is to prevent copying over static (potentionally big) files after every change.

@Deluze aha. so that's reason when i edited some template files in static folder, electron restarted, but nothing change, makes me confusing.

With this feature still exist, I think dev-server.js should stop listening change on static folder

    Chokidar.watch(Path.join(__dirname, '..', 'src', 'main')).on('change', () => {
        restartElectron();
    })

from electron-vue-template.

Deluze avatar Deluze commented on May 15, 2024

Thanks for your clarification. Now I know it's because I develop the application on mac and package on windows, I run npm run build directly instead of running npm run dev, that's why the static files are never being copied.

If someone runs npm run build instead of npm run dev, build/main/static will actually not exist. The build script does not copy the static files, you're correct. Electron Builder pulls the static files directly from the src/main/static.

This would be the new way of referencing static files with your PR (& this wouldn't work on the dev server):

const path = app.getAppPath() + '/build/main/static/myFile.txt'

But I expect that all static files will be available in app.getAppPath() + '/static/...', and this should always work independently of OS & environment (dev, build).

This also works in your situation @zhanglongqi. Perhaps your manual copying breaks this?

from electron-vue-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.