prismicio / javascript-kit

Development kit for the Javascript language
https://developers.prismic.io
106 stars 69 forks source link

Browserify/Webpack module #83

Closed mcrider closed 9 years ago

mcrider commented 9 years ago

Is there a good way to use this kit in a Browserify or Webpack project? I'm not very familiar with the nuts and bolts of their module systems but as far as I can tell this is incompatible.

erwan commented 9 years ago

Hi,

The kit is designed to work both in-browser and with npm. Browserify is designed to use npm modules in the browser.

We haven't tried, but it's worth trying. Maybe it will just behave like any other NodeJS module and just work. But maybe we need to change the way we detect the environment, at the end of each file, for example: https://github.com/prismicio/javascript-kit/blob/master/src/utils.js#L184

In any case, the kit being compatible for use in-browser you can just use it outside of your build. If you keep the version number in the filename and the web server correctly sets a long expiration date, you shouldn't see any impact on performances.

mcrider commented 9 years ago

Thanks, it worked in Browserify with var Prismic = require('prismic.io').Prismic; -- I tried a bit using Webpack, but couldn't get it to work, but didn't really try that hard and have a limited understanding of Webpack so I may have been missing something.

erwan commented 9 years ago

Awesome, good to hear it works out of the box!

chiplay commented 9 years ago

Webpack is still not working out of the box - the LRUCache doesn't get exported properly and is sometimes undefined:

https://www.dropbox.com/s/e55qm20kqev59vx/Screenshot%202015-05-22%2016.18.22.png?dl=0

Would love to see a solution for this!

erwan commented 9 years ago

Thanks chiplay, I'll take a look.

chiplay commented 9 years ago

Thanks @erwan!

chiplay commented 9 years ago

I think wrapping the LRUCache in the same (function (Global, undefined) { ... }(typeof exports === 'object' && exports ? exports : (typeof module === "object" && module && typeof module.exports === "object" ? module.exports : window))); as the rest of the exports will do the trick

erwan commented 9 years ago

I just committed that, could you check and let me know if it fixes it? If yes I will cut a release.

chiplay commented 9 years ago

@erwan perfect - thanks again!