-
-
Save niespodd/1fa82da6f8c901d1c33d2fcbb762947d to your computer and use it in GitHub Desktop.
{... | |
"scripts": { | |
"postinstall": "node patch.js", | |
... | |
} | |
} |
// Angular >= 11 | |
const fs = require('fs') | |
const f = 'node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js' | |
fs.readFile(f, 'utf8', function(err, data) { | |
if (err) { | |
return console.log(err) | |
} | |
var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true, fs: "empty"}') | |
fs.writeFile(f, result, 'utf8', function(err) { | |
if (err) return console.log(err) | |
}) | |
}); | |
// ---- | |
// For Angular <11 | |
const fs = require('fs'); | |
const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js'; | |
fs.readFile(f, 'utf8', function (err,data) { | |
if (err) { | |
return console.log(err); | |
} | |
var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}'); | |
fs.writeFile(f, result, 'utf8', function (err) { | |
if (err) return console.log(err); | |
}); | |
}); | |
// ---- |
This solution doesn't seem to work anymore at least not in angular v13. Check out new solution here
This solution doesn't seem to work anymore at least not in angular v13. Check out new solution here
It should be obvious that it won't work for Angular 14 as well because there is no browser.js file in the path "node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js"
It should be obvious that it won't work for Angular 14 as well because there is no browser.js file in the path
"node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js"
Yes I was modifying browser.js as well, but now it's gone, and I find a new way:
My currently version: @angular/[email protected]", electron": "^24.1.3", "electron-builder": "^23.6.0".
APPROCH 1:
- You need the @angular-builders/custom-webpack, (for me, I just use the latest release and it is ^15.0.0, you may need to adjust in future)
npm install --save-dev @angular-builders/custom-webpack@^15.0.0
- update angular.json:
"your-app-name":{
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./extra-webpack.config.js"
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"browserTarget":"your-app-name:build"
},
...
- extra-webpack.config.js
module.exports = {target:'electron-renderer'}
APPROCH 2: Here again we modify the config file :p
Your scripts now should update this file: node_modules\@angular-devkit\build-angular\src\webpack\configs\common.js
And make sure the target will be replaced to 'electron'-renderer' only.
replace old > target: [isPlatformServer ? 'node' : 'web', 'es2015'],
to > target: ['electron-renderer'],
#14 90.92 Error: Cannot find module '/opt/project/patch.js'
#14 90.92 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
#14 90.92 at Function.Module._load (internal/modules/cjs/loader.js:725:27)
#14 90.92 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
#14 90.92 at internal/main/run_main_module.js:17:47 {
#14 90.92 code: 'MODULE_NOT_FOUND',
#14 90.92 requireStack: []
#14 90.92 }
im having error on jenkins build can someone help me ?