ragingwind / gulp-crisper

gulp plugin for crisper
18 stars 11 forks source link

Support ability to rename output files #10

Closed robdodson closed 8 years ago

robdodson commented 8 years ago

Using crisper I can do something like this: crisper --source index.html --html build.html --js build.js

Is it possible to do the same thing with the gulp task? I'd like to rename my output file from elements.html to elements.vulcanized.html and elements.vulcanized.js.

ragingwind commented 8 years ago

It seems that --html option is only possible for cli of crisper. I think the best way of renaming is that crisper supports both of options like jsFileName . However, For now, We can use gulp-rename and jsFileName option of crisper to rename those of files

robdodson commented 8 years ago

Yeah it seems like if crisper doesn't support it then we should just use a separate gulp task like gulp-rename. Closing this issue for now. Thanks @ragingwind

ksugiarto commented 8 years ago

Hi @robdodson @ragingwind thank for this open issue that pretty much help me. I don't know if my code is wrong but, I tried jsFileName to rename the js file output but seems to be not works. Here is how I code it:

gulp.task('crisper', ['vulcanize'], function() {
  return gulp.src('public/elements/elements.vulcanized.html')
  .pipe(crisper({
    jsFileName: 'elements.vulcanized.uglified.js', // still won't work
    scriptInHead: false, // true is default
    onlySplit: false
  })) 
  .pipe(gulp.dest('public/elements'))
})

For me this feature pretty important since I don't want the other user to change the vulcanized code since after this Crisper I would ulgifying the JS. What should I do?

ragingwind commented 8 years ago

@ksugiarto As I understand that you want to change filename of output files. If it is, you should put gulp-rename task before gulp.dest. jsFileName option for only changing of filename at script block in vulcanized html. Here is sample code for gulp-rename snipped from here. not tested, be sure for using it

return gulp.src('public/elements/elements.vulcanized.html')
  .pipe(crisper({
    jsFileName: 'elements.vulcanized.uglified.js', // still won't work
    scriptInHead: false, // true is default
    onlySplit: false
  })) 
  .pipe($.rename(function(file) {
      if (file.extname === '.js') {
        file.basename = ''elements.vulcanized.uglified.js' ;
      }
    }))
  })
  .pipe(gulp.dest('public/elements'))
ksugiarto commented 8 years ago

Hi @ragingwind thanks for your quick reply. I didn't know it could be that way, pretty awesome and It's works. Sorry, there is some typo, just in case for everybody still look into this issue :)

gulp.task('crisper', ['vulcanize'], function() {
  return gulp.src('public/elements/elements.vulcanized.html')
  .pipe(crisper({
    scriptInHead: false, // true is default
    onlySplit: false
  })) 
  .pipe(rename(function(file) {
    if (file.extname === '.js') {
      file.basename = 'elements.vulcanized.uglified'
    }
  })) 
  .pipe(gulp.dest('public/elements'))
})

So, for the file.basename don't add another .js because it will double the extname. Thanks again anyway.