gulp-browserify icon indicating copy to clipboard operation
gulp-browserify copied to clipboard

Support for aliasMapping

Open karellm opened this issue 10 years ago • 16 comments

Hi,

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

karellm avatar Feb 05 '14 15:02 karellm

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.

deepak1556 avatar Feb 05 '14 16:02 deepak1556

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

greypants avatar Feb 05 '14 19:02 greypants

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

greypants avatar Feb 05 '14 19:02 greypants

@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.

karellm avatar Feb 05 '14 21:02 karellm

@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.

shuhei avatar Feb 06 '14 00:02 shuhei

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

deepak1556 avatar Feb 06 '14 07:02 deepak1556

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 :)

karellm avatar Feb 06 '14 13:02 karellm

+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.

tavisrudd avatar Mar 04 '14 22:03 tavisrudd

+1

nivoc avatar Mar 12 '14 14:03 nivoc

+1

psi-4ward avatar Mar 16 '14 14:03 psi-4ward

+1

BerkeleyTrue avatar Mar 19 '14 03:03 BerkeleyTrue

We really need it!

MaxSvargal avatar Mar 26 '14 13:03 MaxSvargal

+1

nielswind avatar Mar 26 '14 18:03 nielswind

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

deepak1556 avatar Mar 26 '14 19:03 deepak1556

@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?

zsitro avatar Mar 27 '14 19:03 zsitro

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

deepak1556 avatar Mar 27 '14 19:03 deepak1556