I am working on using Zurb Foundation with WebPack and NPM, without Bower.
The problem I am encountering is the same as this below:
https://github.c
I was able to do this with webpack by essentially doing an end-run around loading it as a module.
This is basically a hack though, Foundation really needs to update its JS to be loadable as a commonJS module.
The problem stems from Foundation's JS referencing dependencies in erratic ways from within nested IFFEs in the souce code. Sometimes jQuery is the local jQuery parameter, sometimes it's $, sometimes it's window.jQuery. It's really a mixed-bag. The combination of all the different mechanisms means there's no single shimming solution other than to just load the thing non-modularly.
Honestly it's pretty much amateur hour in there, but as of this writing they just released the thing last week, so hopefully it'll be fixed soon.
Anyhoo... to the hack:
I make a separate vendor bundle and load all the amateur-hour 3rd party npm libraries there because I just get tired of fighting with all the various shimming mechanisms necessary to wrap poorly-shipped open-source npm package code.
My vendor bundle is a separate entry point that I register with webpack, and it contains all the libraries that do not play nice as modules.
require('!!script!jquery/dist/jquery.min.js');
require('!!script!uglify!foundation-sites/js/foundation.core.js');
require('!!script!uglify!foundation-sites/js/foundation.accordion.js');
require('!!script!uglify!foundation-sites/js/foundation.util.keyboard.js');
require('!!script!uglify!foundation-sites/js/foundation.util.motion.js');
// etc.
Make sure you have script-loader installed
npm install script-loader -D
The !! means "Ignore all the other rules I already defined in the config". Using the script-loader tells webpack to load and execute the file in the window scope essentially the same as if you had just included a script tag on your page. (But it doesn't, obviously.)
You could get fancier and write your own resolve rules so that it checks just stuff in the foundation-library, but I didn't bother because I hope a library as pervasive as Foundation gets their act together in the near future so I can just delete this hack.
Also... in your main webpack configuration you will want to reference jQuery and any other global window variables loaded in this way as externals.
var webpackConfig = {
entry: { // blah },
output: { // blah },
loaders: [ // blah ],
externals: {
jquery: "jQuery"
}
};