Web*_*v T 16 javascript concatenation node.js npm
我最近发现我可以使用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'));
});
Run Code Online (Sandbox Code Playgroud)
有没有办法用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/**"
}
}
Run Code Online (Sandbox Code Playgroud)
vor*_*ant 15
试试这个
var concat = require('concat')
concat(['a.css', 'b.css', 'c.css'], 'all.css')
Run Code Online (Sandbox Code Playgroud)
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",
...
},
Run Code Online (Sandbox Code Playgroud)
https://www.npmjs.com/package/concat-glob-cli
您还可以使用 shell 的强大功能来执行您想要的操作:
"scripts": {
"concat": "cat www/js/**/*.js > all.js"},
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12118 次 |
最近记录: |