Multiple node modules in a browserify bundle

ayamflow

I'm working on a client-side project using different dependencies (such as page, superagent, vue). To optimize my grunt-browserify task speed, I would like to create a bundle containing all these dependencies, in one file, such as lib.js. My source will be compiled in app.js. And then I guess I will have to concat both into my build.js. With this setup, grunt will only have to update the app.js and build.js), not the lib.js. That also means that for each dependency included in the lib.js I can still require(dep).

I've read some stuf about it but I can't manage to make it work.

My current browserify task is:

browserify: {
        dev: {
            files: {
                'build/app.js': ['src/**/*.js', 'src/**/*.html']
            },
            options: {
                debug: true,
                external: ['vue', 'superagent', 'page']
            }
        }
    }

and I've tried adding something like that without success:

browserify: { // the dev target is still there
        lib: {
            files: {
                'build/lib.js': ['vue', 'superagent', 'page']
            }
        }
    }

I know it doesn't work because my files object is not correct, however I do not know how to automatically get the main file of each dependeny.

Any help would be appreciated. Thanks !

ayamflow

I finally figured how to do it for bower components (haven't tested yet for npm modules).

First, the libs browserify task (using TweenMax for the example) :

libs: {
    files: {
        'build/public/libs.js': ['bower_components/greensock/src/minified/TweenMax.min.js']
    },
    options: {
        shim: {
            TweenMax: {
                path: 'bower_components/greensock/src/minified/TweenMax.min.js',
                exports: 'TweenMax'
            }
        }
    }
}

Then the application task:

dev: {
    files: {
        'build/public/desktop/desktop.js': ['src/desktop/**/*.js']
    },
    options: {
        external: ['TweenMax']
    }
}

It's important to make shims or aliases for each library. When I first tried to make an external bundle, I was using several browserify transforms (such as debowerify/deglobalify) that were interfering with the external thing.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple node modules in a browserify bundle

From Dev

Browserify, is it possible to bundle common modules into seperate file?

From Dev

Browserify not accessing node_modules

From Dev

How to bundle multiple javascript libraries with browserify?

From Dev

Running multiple transforms on gulp/browserify bundle

From Dev

Browserify - bower vs npm node modules

From Dev

Bundle node.js apps to a single file with Browserify

From Dev

Rails - access node_modules in application.js with browserify rails

From Dev

browserify-shim error when node_modules folder is a symlink

From Dev

Browserify bundle undefined dependency

From Dev

Karma Browserify bundle error

From Dev

Browserify bundle undefined dependency

From Dev

Browserify Requiring Modules within Modules

From Dev

Wallaby with Browserify and TypeScript modules

From Dev

browserify require -g modules

From Dev

Browserify combined with global modules

From Dev

Bundle node_modules for browser and keep "app.js" untouched

From Dev

What the meaning of browserify . -t [envify --NODE_ENV production] | uglifyjs -cm > js/bundle.min.js

From Dev

Browserify bundle.js demystified

From Dev

Browserify - create bundle with external module

From Dev

Grunt browserify transform ReactJS then bundle

From Dev

gulp browserify + reactify not creating bundle

From Dev

List files from browserify bundle

From Dev

browserify command line use default path other than node_modules

From Dev

browserify, jadeify. requiring a jade from a module inside node_modules.. strange behaviour

From Dev

How should I transform ES6 node_modules with browserify and babelify?

From Dev

browserify, jadeify. requiring a jade from a module inside node_modules.. strange behaviour

From Dev

browserify command line use default path other than node_modules

From Dev

invalid directory Users/node_modules/crypto-browserify react native

Related Related

  1. 1

    Multiple node modules in a browserify bundle

  2. 2

    Browserify, is it possible to bundle common modules into seperate file?

  3. 3

    Browserify not accessing node_modules

  4. 4

    How to bundle multiple javascript libraries with browserify?

  5. 5

    Running multiple transforms on gulp/browserify bundle

  6. 6

    Browserify - bower vs npm node modules

  7. 7

    Bundle node.js apps to a single file with Browserify

  8. 8

    Rails - access node_modules in application.js with browserify rails

  9. 9

    browserify-shim error when node_modules folder is a symlink

  10. 10

    Browserify bundle undefined dependency

  11. 11

    Karma Browserify bundle error

  12. 12

    Browserify bundle undefined dependency

  13. 13

    Browserify Requiring Modules within Modules

  14. 14

    Wallaby with Browserify and TypeScript modules

  15. 15

    browserify require -g modules

  16. 16

    Browserify combined with global modules

  17. 17

    Bundle node_modules for browser and keep "app.js" untouched

  18. 18

    What the meaning of browserify . -t [envify --NODE_ENV production] | uglifyjs -cm > js/bundle.min.js

  19. 19

    Browserify bundle.js demystified

  20. 20

    Browserify - create bundle with external module

  21. 21

    Grunt browserify transform ReactJS then bundle

  22. 22

    gulp browserify + reactify not creating bundle

  23. 23

    List files from browserify bundle

  24. 24

    browserify command line use default path other than node_modules

  25. 25

    browserify, jadeify. requiring a jade from a module inside node_modules.. strange behaviour

  26. 26

    How should I transform ES6 node_modules with browserify and babelify?

  27. 27

    browserify, jadeify. requiring a jade from a module inside node_modules.. strange behaviour

  28. 28

    browserify command line use default path other than node_modules

  29. 29

    invalid directory Users/node_modules/crypto-browserify react native

HotTag

Archive