1

I have 6 projects in an Angular workspace and I have to build each. Instead of write six lines in my package.json for each projet, for example : "build_a":" npm run build a" "buiild_b": "npm run build b"

I would like to create only one line like this :

"build_app": "npm run build name="aaa""

How I can do it ?

2 Answers 2

1

you could rely on environment variables in order to discover such names.

however it depends on which operating system you're using on how to define env variables.

"scripts":{
  "build:a":"cross-env NAME=a npm run build",
  "build:b":"cross-env NAME=b npm run build",
  "build:c":"cross-env NAME=c npm run build",
  "build":"browserify src/main.js -o build.js"
}

You would end up with a script section more or less like this.

Sign up to request clarification or add additional context in comments.

Comments

0

Finally I found the solution using a node.js script: build-subproject.js.

const { exec } = require('child_process');
const args = process.argv.slice(2).join(' ');

console.log(`RUNNING build with args: ${args}`);
exec(
  `ng build ${args} && cd dist/${args} && npm pack `,
  (error, stdout) => {
    if (error) {
      console.error(`exec error: ${error}`);
      return;
    }
    console.info(`stdout: ${stdout}`);
  }
);

In package.json,

"build-subproject": "node ./build-subproject.js",

Then run , npm run build-subproject my-project-name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.