webpack钩子调用shell笔记
生活随笔
收集整理的這篇文章主要介紹了
webpack钩子调用shell笔记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
因公司vpn只能在ie里執行的緣故,需要將mac下編譯后內容cp到虛擬機共享目錄下,看效果,簡單實用webpack到plugin鉤子寫了一個插件去執行shell腳本。 1、在webpack配置用引入插件 const cp = require("./你的目錄/cp.js"); 2、在plugins數組中加入此控件并配置
調用
new cp( //copy[{from:"/Users/mazhenxiao/yuanyang/sinoocean/NationalMarketing/08_Code/Webapp/public",to:"/Volumes/sinoocean/public",arg:"-r"])//自定義插件 復制代碼| from | copy自 |
| to | copy 到 |
| arg | "默認參數 -r 覆蓋" |
源碼
/*** 處理執行cp到服務器發布*/ const fs = require("fs"); const childProcess = require("child_process"); const util = require("util"); const os = require('os'); let exec = childProcess.exec; class cp {constructor(arg){this.list = arg||[];}apply(compiler){let th = this;compiler.plugin("done", (compilation)=>{setImmediate(arg=>{th.copy();})}); }copy(){let arr = [];let iswin = os.platform().includes("win32");this.list.forEach(parame=>{arr.push(new Promise((resolve,reject)=>{let str = `${iswin? "copy":"cp"} ${parame["arg"]? parame["arg"]:"-r"} ${parame["from"]} ${parame["to"]}`exec(str,arg=>{if(!arg){resolve()}else{reject();}})}))})Promise.all(arr).then(arg=>{console.log(arg);}).catch(e=>{// console.log(e)})} } module.exports = cp; 復制代碼 新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
以上是生活随笔為你收集整理的webpack钩子调用shell笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 考虑 PHP 5.0~5.6 各版本兼容
- 下一篇: IntelliJ IDEA 15发布