(FRONT) FRONT (2024)

Node PostProcessor step for Angular and Electron.

If we try to start in Electron environment program created by Angular - we receive error, because Electron don't understand where is root of application:



Therefore we need to little bit changing link in HTML (add "./"). This is "post-processor" step in my Angular-Electron template https://github.com/Alex1998100/AngularElectron/tree/PostProcessor.



Something tiny program what adding "./" to result of Angular.


   1:  const fs = require('fs');
   2:  const path = require('path');
   3:   
   4:  const indexPath = path.join(__dirname, '..', 'dist', 'angular-electron1', 'browser', 'index.html');
   5:   
   6:  function updateIndexHtml() {
   7:    try {
   8:      let html = fs.readFileSync(indexPath, 'utf-8');
   9:      if (html.includes('<base href="./"')) {
  10:        console.log('Base href already correct. Skipping update.');
  11:        return;
  12:      }
  13:      html = html.replace('<base href="/"', '<base href="./"');
  14:      html = html.replace(/ (href|src)="([^"]+)"/g, (match, attribute, value) => {
  15:        if (value === "favicon.ico") return match;
  16:        if (value.startsWith("./")) return match; 
  17:        return ` ${attribute}="./${value}"`;
  18:      });
  19:      fs.writeFileSync(indexPath, html);
  20:      console.log('index.html updated successfully.');
  21:    } catch (error) {
  22:      console.error('Error updating index.html:', error);
  23:    }
  24:  }
  25:   
  26:  updateIndexHtml();

Post processor is usual template to Vs2022, rarely does a project go without post-processing in this place in Vs2022:



But in Vs Code we should use another way, like in my scenario:


    "scripts": {
    "post-processor": "node ./tools/post-processor.js",
    "electron:start": "npm run build:angular && npm run build:electron-main && npm run post-processor && npx cross-env NODE_ENV=development electron .",



NodeBackend context:




Angular context:




Electron context:



Comments ( )
Link to this page: http://www.vb-net.com/NodePostProcessor/Index.htm
< THANKS ME>