Closed stubailo closed 7 years ago
Never mind, the require option actually works already, it's just not documented lol. Going to document it in a sec
OK I think the external option might be the same ... hooray for undocumented options...
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?
The example app has it added explicitely as well: https://github.com/meteor/react-packages/blob/master/examples/react-todos/.meteor/packages
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"
}
}
}
}
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 !
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. :)
Added some code plus documentation for: ignore, exclude, external, and plugin. That doesn't contain 'require' tho. Almost.
Newer Meteor doesn't require this plugin (thank you MDG).
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