laravel-elixir-browserify icon indicating copy to clipboard operation
laravel-elixir-browserify copied to clipboard

Generate multiple file with require & external

Open benji07 opened this issue 9 years ago • 0 comments

Hi,

I'm trying to find a way for generating 3 files using elixir and browserify (with shared dependencies)

My 3 files

  • main.js
  • photos.js
  • news.js

Those 3 files require jquery and i would like to only load it once. (On some pages, i will load only main.js, but on other pages, i will load main & photos.js)

Using only Browserify i could use the external & require method, but i can't use them with elixir

I'm trying to achieve something like this:

elixir(function (mix) {
    mix
        .browserify('main.js', null, null, {require: ['jquery']})
        .browserify('photos.js', null, null, {external: ['jquery']})
        .browserify('news.js', null, null, {external: ['jquery']})
    ;
});

If I add this code

if (data.options.external) {
    stream.external(data.options.external);
}

at the end of your browserifyStream function, it work fine, but is there a better way to do it ? (browserify don't expose an external options)

benji07 avatar Oct 14 '16 13:10 benji07