zoukankan      html  css  js  c++  java
  • [NPM] Create a bash script to replace a complex npm script

    In this lesson we will look at pulling out complex npm scripts into their own external bash scripts. This ends up simplifying your package.json file and abstracts the complexity into another file.

    From:

        "pretest": "npm run lint",
        "test": "BABEL_ENV=test mocha spec/ --require babel-register",

    To:

    1. Create "scripts" folder and "test.sh" file:

    #!/usr/bin/env bash
    
    npm run lint
    BABEL_ENV=test mocha spec/ --require babel-register

    Then update package.json

    "test": "./scripts/test.sh",

    and remove "pretest" script.

    2. Add premisson to the bash files:

    cd scripts
    chmod -R 777 . // change premission for all files in script folder

    3. Can add some messages:

    From :

    "build": "npm-run-all build:*",
        "prebuild": "rm -rf public/$npm_package_version",
        "build:html": "pug --obj data.json src/index.pug --out public/$npm_package_version/",
        "build:css": "node-sass src/index.scss | postcss -c .postcssrc.json | cssmin > public/$npm_package_version/index.min.css",
        "build:js": "mustache data.json src/index.mustache.js | uglifyjs > public/$npm_package_version/index.min.js",

    TO:

    "build": "./scripts/build.sh",
    #!/usr/bin/env bash
    
    echo "Building..."
    rm -rf public/$npm_package_version
    pug --obj data.json src/index.pug --out public/$npm_package_version/
    node-sass src/index.scss | postcss -c .postcssrc.json | cssmin > public/$npm_package_version/index.min.css
    mustache data.json src/index.mustache.js | uglifyjs > public/$npm_package_version/index.min.js
    echo "Finished building."
  • 相关阅读:
    Keepalived安装配置
    Playbook 角色(Roles) 和 Include 语句
    Ansible Playbook
    ansible的Ad-hoc命令
    Android线程简介
    宝岛探险,DFS&BFS
    再解炸弹人,dfs&bfs
    解救小哈——bfs广搜
    解救小哈——dfs深搜
    数的全排列
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6390395.html
Copyright © 2011-2022 走看看