在学gulp工具,参考这个博客文章敲的代码
在npm把
gulp
和gulp-uglify
都安装了,然后运行gulp
命令,出现如下错误:
$ gulp
[18:01:43] Using gulpfile E:\workspace_node\gulpDemo\gulpfile.js
[18:01:43] Starting 'default'...
[18:01:43] 'default' errored after 5.39 ms
[18:01:43] ReferenceError: uglify is not defined
at Gulp.<anonymous> (E:\workspace_node\gulpDemo\gulpfile.js:4:9)
at module.exports (E:\workspace_node\gulpDemo\node_modules\.0.3.8@orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (E:\workspace_node\gulpDemo\node_modules\.0.3.8@orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (E:\workspace_node\gulpDemo\node_modules\.0.3.8@orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (E:\workspace_node\gulpDemo\node_modules\.0.3.8@orchestrator\index.js:134:8)
at C:\Users\Administrator\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:394:7)
app.js代码:
console.info("hello wolrd gulp");
gulpfile.js
var gulp = require('gulp');
gulp.task('default',function(){
gulp.src('app.js')
.pipe(uglify())
.pipe(gulp.dest('dist/'));
});
你还要多加一句,不然gulp不知道uglify是什么东东哦:
然后gulp有专门适配的
gulp-uglify
插件,一般应该是用gulp-uglify
的吧