2017-07-19 53 views
0

喜後,我用npm install jquery安裝一個jQuery我project.but我發現這是位於node_modules \ jQuery的有許多不需要的文件。如何使用jquery運行「故宮安裝jQuery的」

,但我只是瓦納把node_modules \ jQuery的\ DIST \ jquery.min.js靜態\ jQuery的文件夾

什麼是最好的和通用的方式?手動複製並粘貼?

+0

您是否使用構建系統(如gulp或grunt)?如果是這樣,他們將允許您複製該文件或將其合併到一個連接的腳本中。 – mingos

回答

1

你可以使用npm來做到這一點。在你package.json,添加以下到scripts關鍵

... 
"scripts": { 
    "build:jquery": "cp node_modules/jquery/dist/jquery.slim.min.js static/jquery/" 
}, 
... 

然後你可以運行:npm run build:jquery

您可以添加更多的建設任務,到本節,你需要他們如複製圖像和涅槃的腳本和CSS ,然後把它們結合在一起在一個單一的命令npm-run-all

$ npm install npm-run-all --save-dev 

而且......

... 
"scripts": { 
    "build:jquery": "cp node_modules/jquery/dist/jquery.slim.min.js static/jquery/", 
    "build:images": "cp -R src/assets/images/ static/images/", 
    "build": "npm-run-all -p build:*" 
}, 
... 

然後運行npm run build

NPM是一個偉大的構建工具,往往繞過額外的構建框架,如咕嘟咕嘟或咕嚕的需要。它還可以處理文件觀察者等,以便在事情自動修改時重建。