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."
  • 相关阅读:
    如何在linux系统中设置静态ip地址
    spring 学习
    java 反射机制和invoke方法
    CentoS7装机
    eclipse 添加jar包的方式
    No-args constructor for class does not exist. Register an InstanceCreator with G
    freemarker页面如何获取绝对路径basePath
    MySQL备份还原
    MySQL用户授权与权限
    CentOS7修改SSH远程连接端口
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6390395.html
Copyright © 2011-2022 走看看