esamattis / browserify-externalize

Create external Browserify bundles for lazy asynchronous loading
https://npmjs.org/package/externalize
MIT License
73 stars 3 forks source link

How about package.json directive. #1

Open ghost opened 11 years ago

ghost commented 11 years ago

Nice extension, if there's some package.json directive, it will be even more handy.

esamattis commented 11 years ago

Can you provide an example how it would work?

ghost commented 11 years ago

For example:

{
    "name" : "browser-badge",
    "version" : "1.1.0",
    "description" : "generate browser version compatibility badges",
    "main" : "index.js",
    "bin" : {
        "browser-badge": "bin/cmd.js"
    },
    "directories" : {
        "example" : "example"
    },
    "dependencies" : {
        "canvas" : "~0.13.1",
        "optimist" : "~0.3.4",
        "syntax-error" : "~0.0.0",
        "through" : "~0.1.4"
    },
    "externalize": ["canvas", "optimist"],
    "repository" : {
        "type" : "git",
        "url" : "git://github.com/substack/browser-badge.git"
    },
    "homepage" : "https://github.com/substack/browser-badge",
    "keywords" : [
        "browser",
        "badge",
        "png",
        "compatibility",
        "version"
    ],
    "author" : {
        "name" : "James Halliday",
        "email" : "mail@substack.net",
        "url" : "http://substack.net"
    },
    "license" : "MIT"
}

The canvas and optimist modules will be separated from main bundle.

esamattis commented 11 years ago

I don't quite get it yet. Is this supposed to be the project package.json or a dependency package.json?

And even on both cases to which bundle would those modules (canvas, optimist) be externalized to?

ghost commented 11 years ago

Yes, this is the project package.json. Suppose we want to conditionally load the canvas and optimist. After the build process, there will be three bundles, canvas and optimist have their own bundles which have been externalized from project bundle.