Skip to content

Instantly share code, notes, and snippets.

@appsforartists
Created September 9, 2014 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsforartists/55b65f291aeda8174b80 to your computer and use it in GitHub Desktop.
Save appsforartists/55b65f291aeda8174b80 to your computer and use it in GitHub Desktop.
Hiding server-side dependencies from Webpack
var jsdom; // populated later if contextIsBrowser fails
var utilities = {
"domify": function (node) {
if (!node["getElementsByTagName"]) {
node = jsdom(node);
}
return node;
},
"contextIsBrowser": function () {
var getGlobalScope = function () {
return this;
};
return getGlobalScope().hasOwnProperty('window');
}
};
if (!utilities.contextIsBrowser()) {
jsdom = require('jsdom').jsdom;
}
module.exports = utilities;
//…
"plugins": [
new Webpack.IgnorePlugin(/jsdom/)
],
// …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment