ef4 / ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
MIT License
172 stars 28 forks source link

Importing .json files #26

Closed knownasilya closed 8 years ago

knownasilya commented 9 years ago

Says it cannot find the module, tried

import boundaries from 'npm:./nyneigh';
// and
import boundaries from 'npm:./nyneigh.json';

although changing it to .js and adding an export default works

ef4 commented 9 years ago

It works without the relative path prefix.

I'm not even sure what ./ should mean in this context. What is the directory layout between the importing JS file and the json file?

knownasilya commented 9 years ago

app/config/config.js imports app/config/nyneigh.json.

Without the relative prefix wouldn't it try to fetch from node_modules?

ef4 commented 9 years ago

That is a creative use of ember-browserify that I had not considered. Unfortunately it doesn't work because the app tree gets processed by ember-cli before ember-browserify does its thing, and ember-cli does not propagate JSON files.

It looks like https://github.com/ProlificLab/ember-cli-json-to-js may do what you want, but I haven't tried it.

knownasilya commented 9 years ago

@ef4 that will probably not work, since it will process the file as js, and if the file is bigger then 100kb, it hangs the cli (at least in 0.2.2, not in 0.1.15).

ef4 commented 9 years ago

This is a terrible hack, but you could actually do:

import boundaries from 'npm:../../app/config/nyneigh.json'

It works because the lookup happens relative to the temp directory, which just happens to be something like tmp/some-broccoli-filter-XXXXX, so up two levels gets you back to your application's root, and then you can go back down to the source files.

ef4 commented 9 years ago

Also, if there's not already an ember-cli issue tracking the hang over 100k, please file one. Seems bad.

knownasilya commented 9 years ago

@ef4 that's pretty clever.

I actually opted to serve the file from the server by appending it to window on initial request, and that fixes my slow build/hang.

I'll see if I can reproduce the hang on a clean slate without ember-browserify, then submit an issue if I can.

stefanpenner commented 9 years ago

I'll see if I can reproduce the hang on a clean slate without ember-browserify, then submit an issue if I can.

this would be best.

I suspect some massive file is getting transpiled, which isn't hanging but actually taking ages. It is worth trying to transpile those files independently and figure out what the issue is

knownasilya commented 9 years ago

@stefanpenner it is, but the fact is that it worked in 0.1.15 (initial build was like 1.5 min), but in 0.2.2 it hangs indefinitely.

stefanpenner commented 9 years ago

@stefanpenner it is, but the fact is that it worked in 0.1.15 (initial build was like 1.5 min), but in 0.2.2 it hangs indefinitely.

babel/browserify/esperanto/es3-recast upgrade?

can you share the file with me (privately if needed)

knownasilya commented 9 years ago

@stefanpenner https://gist.github.com/knownasilya/026d300f55a94903e07d

stefanpenner commented 9 years ago

I'm just out for dinner. If I haven't responded by Thursday morning I forgot. Please pester me

stefanpenner commented 8 years ago

will reopen if this is still relevant

redbmk commented 7 years ago

@ef4 Sorry for bringing this up here - just found this dirty hack you mentioned (import boundaries from 'npm:../../app/config/nyneigh.json') which worked great for me to load json. Do you know why it is that ember can't load json files natively but ember-browserify can? I'd love to at least be able to install a module (ember-json-exports or something) but the closest I could find was ember-json-module which actually creates a .js file for every .json file (which ended up overwriting a handful of my files! - thank goodness for source control).

Anyway, does it make more sense for ember-browserify to handle all json files or to make a new module that handles them in a similar way to ember-browserify, but dealing with relative paths instead of node modules?

ef4 commented 7 years ago

@redbmk It's because ember-cli is passing all the Javascript files to ember-browserify, but not any accompanying JSON files. So by the time browserify runs it only see JS.