Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Last active February 12, 2024 00:37
Show Gist options
  • Save unscriptable/4707652 to your computer and use it in GitHub Desktop.
Save unscriptable/4707652 to your computer and use it in GitHub Desktop.
should curl.js support non-modules natively?

Q: should curl.js support non-modules natively?

from original Pull Request

Proposal:

code is here

  • Auto-define a module if dev includes a ".js" extension (inject a noop factory: function () {})
  • Fail if the dev used a ".js" extension with modules (define()s found in file)
  • Fail if the dev forgot the ".js" ext on a non-module file

Pros:

  • Allows use of run.js as a non-module
  • Allows simple inclusion of non-modules without the js! plugin
  • The js! plugin and the shim config could still be used for non-modules with dependencies

Cons:

  • Newb confusion? Will noobs start thinking they can specify ".js" at the end of the module id?
  • Will this prolong support for non-modules?
  • Will folks think it will behave like RequireJS? (it won't because curl will use the paths mappings)
@unscriptable
Copy link
Author

agree about the curl global. that's why i like this:

define('run', ['curl'], function (curl) { ... });

Interestingly, I think a named module will work in every situation:

  1. separate script elements, unbundled / dev
  2. separate script elements, bundled / prod
  3. one script element, unbundled / dev
  4. one script element, bundled / prod

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