Skip to content

Instantly share code, notes, and snippets.

@chenglou
Last active August 29, 2015 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenglou/8701065 to your computer and use it in GitHub Desktop.
Save chenglou/8701065 to your computer and use it in GitHub Desktop.
CommonJS-style Asset Bundling

The rough underlying implementation is more or less done. Right now we're deciding betwen two forms, require('a.png') vs. requireStatic('a.png').

require('a.png')

  • Pros: more familiar. One single require for assets too.
  • Cons: Doesn't follow the CommonJS specs. Overloads require.

requireStatic('a.png')

  • Pros: isn't tied to CommonJS.
  • Cons: another thing to learn.
@sophiebits
Copy link

What does it return – the file contents? a URL? If the latter, I definitely think require is wrong; otherwise I don't have a strong opinion.

@chenglou
Copy link
Author

chenglou commented Feb 5, 2014

Requiring an image returns the image path. Requiring a css returns an object that maps from the class name to a (possibly) namespaced class name.
<div className={a['.class']} />

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