How do I add comments to package.json for npm install?

后端 未结 20 1378
悲哀的现实
悲哀的现实 2020-12-07 07:30

I\'ve got a simple package.json file and I want to add a comment. Is there a way to do this, or are there any hacks to make this work?



        
20条回答
  •  臣服心动
    2020-12-07 08:03

    NPS (Node Package Scripts) solved this problem for me. It lets you put your NPM scripts into a separate JavaScript file, where you can add comments galore and any other JavaScript logic you need to. https://www.npmjs.com/package/nps

    Sample of the package-scripts.js from one of my projects

    module.exports = {
      scripts: {
        // makes sure e2e webdrivers are up to date
        postinstall: 'nps webdriver-update',
    
        // run the webpack dev server and open it in browser on port 7000
        server: 'webpack-dev-server --inline --progress --port 7000 --open',
    
        // start webpack dev server with full reload on each change
        default: 'nps server',
    
        // start webpack dev server with hot module replacement
        hmr: 'nps server -- --hot',
    
        // generates icon font via a gulp task
        iconFont: 'gulp default --gulpfile src/deps/build-scripts/gulp-icon-font.js',
    
        // No longer used
        // copyFonts: 'copyfiles -f src/app/glb/font/webfonts/**/* dist/1-0-0/font'
      }
    }
    

    I just did a local install npm install nps -save-dev and put this in my package.json scripts.

    "scripts": {
        "start": "nps",
        "test": "nps test"
    }
    

提交回复
热议问题