Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output filename different than input #34

Closed
markgoodyear opened this issue Dec 2, 2013 · 17 comments
Closed

Output filename different than input #34

markgoodyear opened this issue Dec 2, 2013 · 17 comments

Comments

@markgoodyear
Copy link

Would it be possible to specify a different output file than the source file? For example, my project requires specifying a main.css file, along with a minified version, main.min.css.

gulp.task('minifycss', function() {
    gulp.src('./dist/assets/css/main.css')
        .pipe(minifycss())
        .pipe(gulp.dest('./dist/assets/css/main.min.css'));
});

Obviously the above doesn't work — it just creates a folder called main.min.css then puts the output file inside, but something like the above would be great.

Cheers,
Mark

@yocontra
Copy link
Member

yocontra commented Dec 2, 2013

This seems like a good case for gulp-rename. gulp.dest is specifically for folders - we used to have a .file output but that was removed

Proposed:

gulp.task('minifycss', function() {
    gulp.src('./dist/assets/css/main.css')
        .pipe(minifycss())
        .pipe(rename('main.min.css'))
        .pipe(gulp.dest('./dist/assets/css/'));
});

This also gives me an idea for a gulp-extrename plugin that changes the extension of any file passed through

@hparra
Copy link

hparra commented Dec 3, 2013

A rename function would be in the piping spirit, but it should be more powerful than the proposed. It should offer all the globbing business addressed by #6 and #7.

I added a filename function to gulp-cli. I'm not crazy about that pattern. Would prefer some sort of smart string.

@yocontra
Copy link
Member

yocontra commented Dec 3, 2013

@hparra Would you mind renaming that to gulp-spawn? I was planning on using gulp-cli to split out that section of code soon

For the rename plugin you could have a few different ways. String for simple rename, object like {extension: '.min.css'} to just change an extension, or a function that takes in the existing name and returns the new name. I can't think of any cases that wouldn't be covered by those.

Other plugins could use this rename plugin to rename files, change file extensions, etc. by piping their existing output through it

@hparra
Copy link

hparra commented Dec 3, 2013

@contra Yeah. That's exactly the way it should work - takes hash of helpful params like "extension", "prefix", "suffix", or a function to roll your own deal, e.g. regex, etc.

RE: gulp-cli. I unpublished it. You should probably go ahead and sit on entry.

@yocontra
Copy link
Member

yocontra commented Dec 3, 2013

@hparra I got chastised by isaacs for camping a plugin before while I was working on the code. I'll just hope nobody is a dick and takes it.

@yocontra
Copy link
Member

yocontra commented Dec 3, 2013

Also @hparra feel free to make gulp-rename yourself if you want! The idea is pretty straightforward and there is already code for renaming extensions and whatnot in gulp-util

@markgoodyear
Copy link
Author

@contra @hparra I like the idea of rename, sounds just what I'm after. Changing the extension also works too, might actually be a better solution for specifying .min.css, saves from re-specifying the main file name.

@yocontra
Copy link
Member

yocontra commented Dec 4, 2013

Putting out a bounty of $5 to anyone who wants to make gulp-rename

@hparra
Copy link

hparra commented Dec 4, 2013

Sorry, I was going to do this since I already did that filename business, but I got side-tracked just building the yeoman generator.

Proposal: it accepts a string for explicit rename, or a hash with options for common operations (prefix, suffix, extension) relative to the original filename, or a custom function.

@yocontra
Copy link
Member

yocontra commented Dec 4, 2013

@hparra Exactly what I had in mind

@hparra
Copy link

hparra commented Dec 4, 2013

@contra Me too. Will get to it later tonight.

@yocontra
Copy link
Member

yocontra commented Dec 4, 2013

#37

@hparra
Copy link

hparra commented Dec 4, 2013

@markgoodyear Released as gulp-rename.

@contra I guess you can close this!

@markgoodyear
Copy link
Author

@hparra Tested, and works great. I use the same method for minifying JS, so the .pipe(rename({suffix: '.min'})) is perfect for both cases — no need to worry about re-specifying file name/type. Good work! 👍

@yocontra
Copy link
Member

yocontra commented Dec 4, 2013

Nice! @hparra DM me your gmail so I can send you a wallet payment

@yocontra yocontra closed this as completed Dec 4, 2013
@jurchiks
Copy link

jurchiks commented Apr 25, 2016

This really should be built-in functionality... It is extremely common to output files in the format name.min.ext.

@phated
Copy link
Member

phated commented Apr 25, 2016

No, it should not, use gulp-rename.

@gulpjs gulpjs locked and limited conversation to collaborators Apr 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants