esperantojs / esperanto

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

Question: import pkg from '../package.json' #163

Closed clintwood closed 9 years ago

clintwood commented 9 years ago

If there is a ./package.json in ./ and I bundle ./lib/index.js to CJS where

// lndex.js
import pkg from '../package.json';

I get the following out

var pkg = require('package.json');

Notice that it has lost the ../. is this expected? How to get the ../ to stay?

Rich-Harris commented 9 years ago

Can you share the exact configuration you're using? I get a different result with esperanto 0.6.33 (latest version - if I run esperanto -i lib/index.js -o dist/index.js -t cjs, or anything similar, the ../ is preserved, so I'm not quite sure what's going on here

clintwood commented 9 years ago

Ya, sorry should have mentioned, this only occurs if you specify the -b flag for bundling (add -b to what you have there)!

Hmmm... now that I think of it I'm not sure how much sense it makes to reference a json file from inside a bundle (which would usually be shipped as a lib)!

Rich-Harris commented 9 years ago

Will close this now that Rollup is taking over from Esperanto. It'd definitely be possible to do this in Rollup via custom resolvers/loaders – only real question is to what extent things like this should work out of the box. Not sure what the answer is. Feel free to open a similar issue over on the Rollup issue tracker!