Comments (6)
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.
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.
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.
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 .
from electron-vue-template.
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.
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 runningnpm 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)
- How to use static files? HOT 2
- Suggestion: add debug information for VSCode HOT 1
- Suggestion: PR adding Eslint, VueTSC and automatic checkers? HOT 1
- Use axios when app is build HOT 2
- SQLite Database HOT 1
- How to integrate Element-Plus or View-UI-Plus framework for this template? HOT 4
- Runtime Errors HOT 2
- I can't load `.ts` file in another `.ts` file. HOT 6
- static resource not found on build HOT 3
- [!] Read before submitting
- tray icon path HOT 6
- How to listen for webContents.send events from main processes in vue components HOT 3
- Dependecies are out of date
- 6 high severity vulnerabilities HOT 2
- __name is not define HOT 1
- Can we add IPC practice in this template? HOT 1
- Question: How to access electron-store in vue HOT 3
- for someone who needs to use@electron/remote
- How to use three.js to load `.glb` 3D model in Electron?
- Error: Not allowed to load local resource
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron-vue-template.