From ec705ee30170a5edd21b3cfba4e3dd50a94d40df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=AD=90=E6=98=93?= Date: Tue, 26 Jun 2018 20:23:27 +0800 Subject: [PATCH] Allow Angular Using Electron Modules --- package.json | 2 +- postinstall.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 postinstall.js diff --git a/package.json b/package.json index 83702da4f..1988634c5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "main": "main.js", "private": true, "scripts": { - "postinstall": "npx electron-builder install-app-deps", + "postinstall": "npx electron-builder install-app-deps && node postinstall", "ng": "ng", "start": "npm-run-all -p ng:serve electron:serve", "build": "npm run electron:tsc && ng build", diff --git a/postinstall.js b/postinstall.js new file mode 100644 index 000000000..a1c8b5f0e --- /dev/null +++ b/postinstall.js @@ -0,0 +1,15 @@ +// Allow angular using electron module (native node modules) +const fs = require('fs'); +const f_angular = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js'; + +fs.readFile(f_angular, 'utf8', function (err, data) { + if (err) { + return console.log(err); + } + var result = data.replace(/target: "electron-renderer",/g, ''); + var result = result.replace(/return \{/g, 'return {target: "electron-renderer",'); + + fs.writeFile(f_angular, result, 'utf8', function (err) { + if (err) return console.log(err); + }); +}); \ No newline at end of file