zont / gulp-usemin

MIT License
338 stars 92 forks source link

add pathTransform option #159

Closed konclave closed 8 years ago

konclave commented 8 years ago

In build block I've got source files paths that don't match real files. I.e. with added revision in a template.

<!-- build:js static/scripts/app.min.js -->
    <script src="static/scripts/app.js?{{REVISION}}"></script>
    <script src="static/scripts/utils/filters/truncatechars.js?{{REVISION}}"></script>
    .
    .
    .
<!-- endbuild -->

In that case gulp-usemin doesn't find source files and fails. pathTransform option is a function that transforms source file string to make it match the real path. It doesn't transform destination file path.

gulp.task('build', function() {
  return gulp.src('index.html')
    .pipe(gulp-usemin({
        path: './',
        pathTransform: function(path) {
          return path.replace('?{{REVISION}}', '');
        },
        js: [uglify()],
     }))
     .pipe(gulp.dest('./');
});
zont commented 8 years ago

Please use another plugin for this. gulp-replace:

var usemin = require('gulp-usemin');
var replace = require('gulp-replace');

gulp.task('usemin', function(){
  return gulp.src('./*.html')
    .pipe(replace('?{{REVISION}}', ''))
    .pipe(usemin({}))
    .pipe(gulp.dest('build/'));
});