有时需要在运行npm run时,执行多个自定义的任务,此时可以使用增加scripts中条目,然后用一个总任务脚本将相关条目用&&串联起来的方式进行。标签:npm,run,package,js,build,scripts,css From: https://blog.51cto.com/JohnsonJu/6089176
我们知道:在package.json中
,scripts里的条目可使用:npm run XXX(脚本关键字)来自动执行。
通常情况下,我们在生产环境下,只需运行npm run build。如是本地开发,就用npm run watch。
比如在package.json中:
{
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --inline --hot",
"build": "webpack -p"
},
"author": "Johnson Ju <[email protected]>",
"license": "MIT",
"devDependencies": {
……
},
"dependencies": {
"vuetable": "git://github.com/ratiw/vue-table.git#develop"
}
}
在"scripts": {...}条目里有一句:
"build": "webpack -p",使用webpack打包。
"build-js"和 "build-css",分别类似这样子的:
"build-js": "browserify browser/main.js | uglifyjs -mc > static/bundle.js",
"build-css": "cat static/pages/*.css tabs/*/*.css",
然后,通过另一条脚本将上面串联起来(注意中间用了“&&” 连接):
"build": "npm run build-js && npm run build-css",
npm run build 即可将 build-js和build-css任务同时自动完成了。
{
"main": "index.html",
"scripts": {
},
"author": "Johnson Ju <[email protected]>",
"license": "MIT",
"devDependencies": {…… },
"dependencies": {
"vuetable": "git://github.com/ratiw/vue-table.git#develop"
}
}