ck86 / gulp-bower-files

Build gulp.src() of your bower packages main files.
80 stars 13 forks source link

Normalize Vinyl files before outputting the Stream #27

Closed franleplant closed 10 years ago

franleplant commented 10 years ago

Hi!

When I run

gulpBowerFiles()
  .pipe(gulp.dest("./dist"));

I get in ./dist directory something like this

dist
    -- jquery/dist/jquery.js
    -- bootstrap/dist/scripts/bootstrap.js
   ...

I had to apply this home made normalize function

Normalize

var normalize = through.obj(function (file, enc, cb){
    //Normalize the paths of Bower files
    file.base = path.dirname( file.path );
    this.push(file);
    cb();
});

gulpBowerFiles()
  .pipe(normalize)
  .pipe(gulp.dest("./dist"));

to get this running properly and getting this final result

dist
    -- jquery.js
    -- bootstrap.js
   ...

As you can see the Vinyl files that you are sending over the stream have an issue with the file.base attribute.

Let file.path be

/path/to/src/file.js

And file.base is currently something like this

/path/to

So file.relative (or something like file.path - file.base) is something like

src/file.js

Which leads us the this unwanted behavior.

xixixao commented 10 years ago

+1 or at least provide an option in the bower.json to set the output file name (though not sure what to do if the package includes more files). But I think for 99% of cases the basename behavior proposed will do.

ck86 commented 10 years ago

-1

If two or more packages have the same main file(s) defined (e.g. main: "./index.js") it will result in a conflict. There is a good plugin to "fix" this issue: gulp-flatten.

franleplant commented 10 years ago

Hi @ck86! Thanks for that plugin!

I think that this issue is dead!

Fran

xixixao commented 10 years ago

Perfect, thanks for the tip!