usemin dev()无法处理.js文件

时间:2018-05-19 01:48:56

标签: javascript html gulp

我正在使用gulp任务对CSS和JavaScript文件进行版本化和uglify,但它没有对.js文件进行版本控制,我没有解释,因为它不会抛出任何错误或警告。关于如何解决它的任何想法?

// build.js file
var gulp = require('gulp'),
    imagemin = require('gulp-imagemin'),
    del = require('del'),
    usemin = require('gulp-usemin'),
    rev = require('gulp-rev'),
    cssnano = require('gulp-cssnano'),
    uglify = require('gulp-uglify'),
    gutil = require('gulp-util');

gulp.task('deleteDistFolder', function() {
    return del("./dist");
});

gulp.task('optimizeImages', ['deleteDistFolder'], function() {
    return gulp.src(["./travel-app/assets/images/**/*",
                "!./travel-app/assets/images/icons",
                "!./travel-app/assets/images/icons/**/*",
            ])
                .pipe(imagemin({
                    progressive: true,
                    interlaced: true,
                    multipass: true
                }))
                .pipe(gulp.dest("./dist/assets/images"));
});

gulp.task('usemin', ['deleteDistFolder'], function() {
    return gulp.src("./travel-app/index.html")
                .pipe(usemin({
                    css: [  function() {return rev()}, 
                            function() {return cssnano()}
                         ],
                    js: [   function() {return uglify()}, 
                                function() {return rev()}
                        ]
                }))
                
                .pipe(gulp.dest("./dist"))
});

gulp.task('build', ['deleteDistFolder', 'optimizeImages', 'usemin']);
<!-- html blocks -->

  <!-- build:css /assets/styles/styles.css -->
  <link rel="stylesheet" href="temp/styles/styles.css">
  <!-- endbuild -->

  <!-- build:js /assets/scripts/Vendor.js -->
  <script src="/temp/scripts/Vendor.js"></script>
  <!-- endbuild -->

  <!-- build:js /assets/scripts/App.js -->
  <script src="/temp/scripts/App.js"></script>
  <!-- endbuild -->

1 个答案:

答案 0 :(得分:0)

在此处找到解决方案:https://stackoverflow.com/a/50333361/7559928

似乎问题与ES6的使用有关,因此最好使用gulp-uglify-es包。