我最近发现我可以使用 npm 作为任务运行程序而不是 gulp 或 grunt,到目前为止一切都很棒(lint、stylus、jade、uglify、watch .. 等)但是连接部分,我似乎无法实现那。用 gulp 是这样的:
gulp.task('scripts', function() {
return gulp.src('www/js/**/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('www/dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('www/dist'));
});
有没有办法用 npm 做到这一点?
更清楚地说,我的目标是做这样的事情:
//package.json
{
"name": "f_todo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "",
"license": "MIT",
"devDependencies": {
"concat": "^1.0.0",
"rerun-script": "^0.6.0",
"stylus": "^0.53.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"stylus": "stylus ss --compress --out lib/stylesheets",
"concat": "concat dependency code would be here",
"dev": "rerun-script"
},
"watches": {
"stylus": "ss/**"
}
}
最佳答案
试试这个
var concat = require('concat')
concat(['a.css', 'b.css', 'c.css'], 'all.css')
https://www.npmjs.com/package/concat
别忘了npm install concat
通过命令
使用 concat-glob-cli
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"concat": "concat-glob-cli -f path/to/**/*.js -o bundle.js",
...
},
关于javascript - 使用 npm 作为构建工具连接文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35052400/