Gulp没有生成uglified css文件

时间:2018-02-05 12:12:25

标签: node.js npm gulp

我遵循了一个简单的教程并遵循了所有命令,但仍然没有通过gulp在名为“destination”的文件夹中生成uglified css文件。这是代码:

var gulp = require("gulp");
var uglify = require("gulp-uglify");

gulp.task('default', function(){
console.log("gulp is running");

return
gulp.src("source/css/style.css")
.pipe(uglify())
.pipe(gulp.dest('destination'));
});

我的package.json文件包含gulp和gulp-uglify,但是作为dev依赖项:

"devDependencies": {
"gulp": "^3.9.1",
"gulp-uglify": "^3.0.0"}

为什么不在目标文件夹中生成文件?

1 个答案:

答案 0 :(得分:0)

Try this modification:

gulp.task('default', function(){
  return gulp.src("source/css/style.css", {base: "source/css/"})
    .pipe(uglify())
    .pipe(gulp.dest('destination'));
});

Btw, this task only uglifies the file when it's run. Look at tutorials on gulp.watch() to create a task to wait and watch for changes and then uglify the file.