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."
  • 相关阅读:
    spring 注解笔记
    spring boot 拦截器
    spring boot 启动流程及其原理
    Spring之BeanFactory和FactoryBean接口的区别
    微信支付
    三级联动
    搜索分页
    多选标签
    分类界面 大分类小分类
    触底下拉
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6390395.html
Copyright © 2011-2022 走看看