Allow Angular Using Electron Modules

This commit is contained in:
孟子易
2018-06-26 20:23:27 +08:00
parent 1d48e32c73
commit ec705ee301
2 changed files with 16 additions and 1 deletions

View File

@@ -17,7 +17,7 @@
"main": "main.js", "main": "main.js",
"private": true, "private": true,
"scripts": { "scripts": {
"postinstall": "npx electron-builder install-app-deps", "postinstall": "npx electron-builder install-app-deps && node postinstall",
"ng": "ng", "ng": "ng",
"start": "npm-run-all -p ng:serve electron:serve", "start": "npm-run-all -p ng:serve electron:serve",
"build": "npm run electron:tsc && ng build", "build": "npm run electron:tsc && ng build",

15
postinstall.js Normal file
View File

@@ -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);
});
});