Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support excluding modules #5

Closed
nstadigs opened this issue Feb 16, 2014 · 14 comments
Closed

Support excluding modules #5

nstadigs opened this issue Feb 16, 2014 · 14 comments

Comments

@nstadigs
Copy link

First of all: great work!

I would like to be able to exclude modules from the result file. Say that I'm building a plugin for another library, like jQuery or Backbone for example. The plugin would then be dependent of that module, but I would not like to include that module in the package.

A proposal for the interface would be to supply an option called "excludes". The value of the option would be an array of objects:

...
exclude: [
  {moduleName: 'backbone', globalName: 'Backbone'},
  {moduleName: 'jquery', globalName: jQuery}
],
...

That would exclude the modules 'backbone' and 'jquery' from the result, and if the 'exports' options is set these dependencies would be added to the UMD block:

(function (name, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['jquery', 'backbone'], factory);
  } else if (typeof exports === 'object') {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like enviroments that support module.exports,
    // like Node.
    module.exports = factory(require('jquery'), require('backbone'));
  } else {
    // Browser globals (root is window)
    this[name] = factory(jQuery, Backbone); // Names from the globalName options
  }
})

Those modules would then be added to the _require.modules array (no implementation suggestion for this one).

This is just a suggestion, and there might be a better way to implement it. Either way, I would love to have this feature.

Cheers!

@RReverser
Copy link
Owner

Yeah, nice idea.

Thinking about possibility to add both this and module alias as one option like:

link: {
  backbone: {source: 'scope', name: 'Backbone'},
  jquery: {source: 'scope', name: 'jQuery'},
  path: {source: 'module', name: 'path-browserify'}
}

So backbone and jquery will be linked for inner use in Node.js/AMD env with their original names and in browser by given name, and path will be linked and included into code from module with different name (browserified version).

What do you think?

@nstadigs
Copy link
Author

Looks good!

I think that the "scope" thing could be confusing though. At first sight it would tell me that the module should not be loaded as an AMD/node module, but rather from the global scope, when in fact it should only be loaded as a global if AMD/node is not present. I could not think of a better thing to call it myself though.

Anyhow, I think that this is a great way to kill two birds with one stone. :)

@nstadigs
Copy link
Author

maybe you could call it "external"?

link: {
  backbone: {source: 'external', name: 'Backbone'},
  jquery: {source: 'external', name: 'jQuery'},
  path: {source: 'module', name: 'path-browserify'}
}

@RReverser
Copy link
Owner

Maybe. Then other one ('module') could be called 'internal' or 'local'.

@nstadigs
Copy link
Author

Sure :)

@RReverser
Copy link
Owner

Would you like to add this option on your own and send pull request? Such contribution would really help.


From: Niklas Boströmmailto:[email protected]
Sent: ‎17.‎02.‎2014 21:35
To: RReverser/pure-cjsmailto:[email protected]
Cc: Ingvar Stepanyanmailto:[email protected]
Subject: Re: [pure-cjs] Support excluding modules (#5)

Sure :)


Reply to this email directly or view it on GitHub:
#5 (comment)

@nstadigs
Copy link
Author

I'm actually working on it, because I need it. I haven't worked with an AST before though, so it will probably take some time. I will only include the functionality for the external dependencies though. The module aliases would be another feature.

@RReverser
Copy link
Owner

I believe there should be almost no AST work, mostly checking for skipping of some modules. Let me know if you need any help from me.

@nstadigs
Copy link
Author

I have something that works locally now. I'll just have to do some cleanup and extra testing. Hopefully I'll have time to do that tonight.

@RReverser
Copy link
Owner

Could you commit+push even relatively small changes to your fork please so I could track and help you with that?

@nstadigs
Copy link
Author

Alright, done!

There are some broken commits in there, but I will probably squash these before sending a pull request.

@duclet
Copy link

duclet commented Jun 4, 2014

Any updates on this? As far as I'm concern, seems like this is the only missing feature that truly matters.

@RReverser
Copy link
Owner

@duclet Sorry, been working on other features and projects. Will try to get back to this one soon.

@RReverser
Copy link
Owner

@nbostrom @duclet Sorry guys, it has been a long time until I got back to this one, but finally added option for it (with support for custom AMD / global names).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants