esperantojs / esperanto

DEPRECATED: An easier way to convert ES6 modules to AMD and CommonJS
http://esperantojs.org
234 stars 21 forks source link

Bundle JSON (and other things?) #164

Closed Rich-Harris closed 9 years ago

Rich-Harris commented 9 years ago

Via #163... if you have import pkg from './package.json', or similar, then (#163 notwithstanding) it'll get transpiled to the equivalent CommonJS, which works, because the CommonJS gods decided that that was the right thing to do. The equivalent AMD/UMD generated code won't work, but ¯\ (ツ) /¯.

Bundling is a different story however - esperanto doesn't bundle JSON. It just throws an error that it can't find the file (it fails to find package.json.js, so looks for package.json/index.js...), which isn't helpful. Which raises the question of whether esperanto should be able to bundle JSON files. And while we're at it, we may as well consider whether it should be able to bundle other text assets (e.g. HTML), and whether it should work out-of-the-box or whether it should be delegated to loader plugins, possibly with hooks for things like compiling templates. (An easy way to achieve this would be allow an array of transform functions, rather than just the one. First (contents, path) => {...} function to return something wins.)

clintwood commented 9 years ago

As per my (half thought out) comment in #163, I'd suggest a warning message for importing any relative static resources like json since bundling (unless bundling an entire app) is typically only done for module libs?!

Rich-Harris commented 9 years ago

closing as wontfix, per #191