deepak1556 / gulp-browserify

Bundle modules with BrowserifyJS
MIT License
195 stars 45 forks source link

Support for aliasMapping #46

Open karellm opened 10 years ago

karellm commented 10 years ago

Hi,

Do you plan to support aliasMapping like grunt-browserify does? I would definitely use that in my current project. Thanks!

deepak1556 commented 10 years ago

i havnt planned for it but you could use the prebundle callback to achieve it right now. If this is very much needed will add it.

greypants commented 10 years ago

:heart::heart::heart::heart:

greypants commented 10 years ago

@karellm the shortify transform might get you there in the meantime.

karellm commented 10 years ago

@deepak1556 Not sure how I would use it. I tried this without much success:

gulp.task('browserify', function() {
    return gulp.src('app/initialize.coffee', { read: false })
        .pipe(
            browserify({
                transform: ['coffeeify', 'hbsfy'],
                extensions: ['.coffee', '.hbs'],
                insertGlobals : true,
                debug : !gutil.env.production
            })
            .on('prebundle', function(bundler) {
                bundler.require(__dirname + '/app/controllers/home-controller');
            })
        )
        .pipe(rename("frontend.js"))
        .pipe(gulp.dest('public/js'))
});

I need the loaded file to be aliased to controllers/home-controller. FYI, I use chaplin. The library dynamically require the controllers. That's why the aliasMapping comes in handy as it lets you require a full directory.

@greypants Thanks but this doesn't work for my use case. I need to load all the files within a directory without ideally manually listing them.

shuhei commented 10 years ago

@karellm I'm not sure about neither grunt nor chaplin, but as long as I read grunt-browserify's source, aliasMapping just calls require() with expose option. Does this work for you?

bundler.require(__dirname + '/app/controllers/home-controller.coffee', { expose: 'controllers/home-controller' });

If so, we can create a function to call require() based on given config object.

deepak1556 commented 10 years ago

yup @shuhei it does work. but i think it would be nice if we provide config option for aliasmapping :)

karellm commented 10 years ago

Thanks a ton! You made my day!

Support for aliasMapping would still be nice. Right now I need to list my directory manually in my gulpfile which is not very sustainable. I let you see if you wanna close or not :)

tavisrudd commented 10 years ago

+1 for alias mapping directly in the top-level options. It's a core browserify feature. prebundle works but beginners to gulp-browserify have to waste time trying to figure it out.

nivoc commented 10 years ago

+1

psi-4ward commented 10 years ago

+1

BerkeleyTrue commented 10 years ago

+1

MaxSvargal commented 10 years ago

We really need it!

nielswind commented 10 years ago

+1

deepak1556 commented 10 years ago

Sorry i have stopped working on this. This plugin needs a proper rewrite.

zsitro commented 10 years ago

@shuhei expose works fine, ty. @deepak1556 what will be with gulp-browserify in the future? Should we look for alternatives or are you working on it?

deepak1556 commented 10 years ago

Nope i am nt planning on any rewrite. you can look into this thread for suggestions https://github.com/gulpjs/plugins/issues/47