it:ad:npm:howto:define_needed_global_packages_in_package.json_file

IT:AD:npm:HowTo:Define Needed Global Packages In Package.json File

Summary

One important aspect of using IT:AD:NPM and its package.json file, is that the package.json is used to list local dependencies for running the application.

What about global dependencies used for building the application? grunt, gulp,uglify-js are all tools? Turns out that package.json has no section to define such tools – and according to one thread on the net, is never going to add them.

Now…what about if you had to invoke the command from a IT:AD:CLI?

Tricky. Basically, you can't invoke gulp if you haven't installed it globally (so that it creates a gulp.cmd in directory that is part your PATH).

What you can do is is use the script section of the package.json file to map commands which are invokable using npm run <xyx>:

package.json
{
    ...
    "scripts": {
        "gulp": "gulp"
        ...
        //even better -- give commands that provide some distance from the actual tool used:
        "build": "gulp build-prod",
        "develop": "gulp build-dev"    
     }
}

Which can be as follows:

invoke a script
npm run build

A good source for information on how to write scripts – including passing arguments – can be found here: * https://www.sitepoint.com/solve-global-npm-module-dependency-problem/

  • /home/skysigal/public_html/data/pages/it/ad/npm/howto/define_needed_global_packages_in_package.json_file.txt
  • Last modified: 2023/11/04 01:51
  • by 127.0.0.1