How can I write multiline scripts in npm scripts?

后端 未结 3 906
温柔的废话
温柔的废话 2021-02-06 20:37

My package.json looks like the following:

{
  \"name\": \"project\",
  \"version\": \"1.0.0\",
  \"description\": \"\",
  \"main\": \"server.js\",
  \"scripts\":         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 20:41

    Another common alternative is to write an npm command that references a local bash script (where you have more power to do what you want).

    i.e.

    # package.json
    {
      "name": "project",
      "version": "1.0.0",
      "description": "",
      "main": "server.js",
      "scripts": {
        "lint": "./node_modules/eslint/bin/eslint.js --format \"./node_modules/eslint-friendly-formatter/index.js\" .",
        "build:server": "./build-server.sh"
      }
    }
    
    # build-server.sh
    #!/bin/bash
    
    ./node_modules/babel-cli/bin/babel.js . \
      -d dist/server \
      --ignore \
        node_modules,\
        dist,\
        client,\
        public,\
        webpack*
    

    NOTE: make sure you give yourself permission to run the file; otherwise you'll run into permission issues

    sudo chmod 755 'build-server.sh'
    

    See: Run script on mac prompt "Permission denied"

提交回复
热议问题