Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular, Electron, Webpack live reloading

Summary:

I'm trying to create an electron and angular app that uses electron-reload and webpack for live reloading. In my package.json file, I build angular and then run electron which runs the main process and bootstraps angular. In order to start the application, I run the commands: npm start and npm run electron, one after another in separate terminals.

Problem:

The application boots up correctly; however, when I add a change to a file, the electron portion of my app stays intact but the angular portion of my app is lost. Please help.

package.json

{
  "scripts": {
    ...
    "start": "webpack --watch ",
    ...
    "build-electron": "ng build --base-href .  && tsc src\\electron\\electron-main.ts --outDir dist && tsc src\\electron\\logger.ts --outDir dist && tsc src\\electron\\application-menu.ts --outDir dist && copy src\\electron\\package.json dist  && copy src\\electron\\*.html dist",
    "electron": "npm run build-electron && electron ./dist --serve"
  },
  ...
}

File structure

Folder PATH listing for volume Windows
Volume serial number is 000000B3 D831:A351
C:.
|   .angular-cli.json
|   .editorconfig
|   .gitattributes
|   .gitignore
|   karma.conf.js
|   package.json
|   protractor.conf.js
|   README.md
|   tree.txt
|   tsconfig.json
|   tslint.json
|   webpack.config.js
|   WinstonLogging.log
|   
+---dist
|   |   application-menu.js
|   |   electron-main.js
|   |   favicon.ico
|   |   index.html
|   |   inline.bundle.js
|   |   inline.bundle.js.map
|   |   invalid.html
|   |   loading.html
|   |   logger.js
|   |   main.bundle.js
|   |   main.bundle.js.map
|   |   package.json
|   |   polyfills.bundle.js
|   |   polyfills.bundle.js.map
|   |   preferences.html
|   |   styles.bundle.js
|   |   styles.bundle.js.map
|   |   vendor.bundle.js
|   |   vendor.bundle.js.map
|   |   
|   \---assets
|           default.gif
|           quest_logo.png
|           spinner.gif
|           
... <node modules and e2e>
\---src
    |   favicon.ico
    |   index.html
    |   main.ts
    |   polyfills.ts
    |   styles.scss
    |   test.ts
    |   tsconfig.app.json
    |   tsconfig.spec.json
    |   typings.d.ts
    |   
    +---app
    |   |   app-routing.module.ts
    |   |   app.component.html
    |   |   app.component.scss
    |   |   app.component.spec.ts
    |   |   app.component.ts
    |   |   app.module.ts
    |   |   
    |   \---components
    |       +---home
    |       |       home.component.html
    |       |       home.component.scss
    |       |       home.component.spec.ts
    |       |       home.component.ts
    |       |       
    |       \---preferences
    |               preferences.component.html
    |               preferences.component.scss
    |               preferences.component.spec.ts
    |               preferences.component.ts
    |               
    +---assets
    |       .gitkeep
    |       default.gif
    |       spinner.gif
    |       
    +---electron
    |       application-menu.js
    |       application-menu.ts
    |       electron-main.ts
    |       invalid.html
    |       loading.html
    |       logger.ts
    |       package.json
    |       preferences.html
    |       
    \---environments
            environment.prod.ts
            environment.ts
like image 558
S.Park Avatar asked Dec 14 '22 22:12

S.Park


1 Answers

Run ng serve in one terminal and in main.js change

win.loadURL(`http://localhost:4200/index.html`);

then run npm run electron in another terminal

like image 97
Ashok Avatar answered Dec 28 '22 10:12

Ashok