elidoran / cosmos-browserify

Browserify npm modules for client side in Meteor packages
MIT License
78 stars 12 forks source link

Document how to use require and external options #10

Closed stubailo closed 7 years ago

stubailo commented 9 years ago

There are options for the command line tool, but in the API they are methods to call (why is it different? who knows?)

browserify.require: https://github.com/substack/node-browserify#brequirefile-opts

browserify.external: https://github.com/substack/node-browserify#bexternalfile

Probably can be implemented in much the same way as transforms; I know the Grunt plugin has them as JSON options so we can copy that. https://github.com/jmreidy/grunt-browserify#require

stubailo commented 9 years ago

Never mind, the require option actually works already, it's just not documented lol. Going to document it in a sec

stubailo commented 9 years ago

OK I think the external option might be the same ... hooray for undocumented options...

pors commented 8 years ago

It seems that ReactRouter = require("react-router"); only works when cosmos:browserify is explicitely added to the meteor project. It is also part of the react package, but that doesn't do it for me, I get Uncaught ReferenceError: require is not defined in that case.

Any idea how this can be solved?

pors commented 8 years ago

The example app has it added explicitely as well: https://github.com/meteor/react-packages/blob/master/examples/react-todos/.meteor/packages

elidoran commented 8 years ago

You only need cosmos:browserify in your app when you have app files to browserify.

Packages must call api.use('cosmos:browserify', 'client') when they have files they need to browserify.

Each package needing it must call api.use('cosmos:browserify', 'client') for itself; as with all packages.

The react-todos you referenced is an app and has cosmos:browserify in the app scope because it has app files to browserify.

Also, the options file there shows an outdated way to externalify react. Look way down near the bottom of this page to see this:

{
  "transforms": {
    "externalify": {
      "global": true,
      "external": {
        "react": "Package.react-runtime.React.require"
      }
    }
  }
}
pors commented 8 years ago

Ah OK, so to use browserify in an app (as opposed to in a package) it is needed to add cosmos:browserify even though it is part of the react package. That makes things clear, thanks @elidoran !

elidoran commented 8 years ago

Yes, it's the way all packages work. They are scoped to only be available to packages depending on them and an app when added.

Also, there are instructions for using it in an app in the README here. Step 3 says to add cosmos:browserify to your app. :)

elidoran commented 8 years ago

Added some code plus documentation for: ignore, exclude, external, and plugin. That doesn't contain 'require' tho. Almost.

elidoran commented 7 years ago

Newer Meteor doesn't require this plugin (thank you MDG).