This is a file named myFile.js I execute with node:
var aa = `npm run build -- --main=src/` + (component === `widget` ? `thisPath/` : ``) + `${component}/myFile.ts`;
execSync(`${aa} `);
This is in a foreach loop, value of 'component' changes in each loop.
And this is the build command in my package.json:
"build": "ng build --aot --outputHashing=\"all\" --sourceMap=false --vendorChunk=false --extra-webpack-config elements-webpack.config.js --single-bundle"
And this is my elements-webpack.config.js file:
const path = require('path');
const uuidv1 = require('uuid/v1');
console.log(process.argv);
var pathData = process.argv[10];
module.exports = {
output: {
filename: pathData === 'main' ? '[name].[contenthash].js' : '[name].[contenthash].js',
jsonpFunction: 'myElements-' + uuidv1(),
library: 'elements'
},
externals: {
"rxjs": "rxjs",
"@angular/core": "ng.core",
"@angular/common": "ng.common",
"@angular/common/http": "ng.common.http",
"@angular/platform-browser": "ng.platformBrowser",
"@angular/platform-browser-dynamic": "ng.platformBrowserDynamic",
"@angular/compiler": "ng.compiler",
"@angular/elements": "ng.elements",
"@angular/forms": "ng.forms",
"@angular/router": "ng.router"
}
};
What I want to do is send a parameter from myFile.js to the command in package.json so that I get it in the webpack config file. The parameter is the value of the 'component' variable.
I think it should look like this:
var aa = `npm run build -- --main=src/` + (component === `widget` ? `thisPath/` : ``) + `${component}/myFile.ts` + ` ${component}`;
But then I dont know how to catch it in package.json.