Skip to content

Instantly share code, notes, and snippets.

@b-barry
Last active July 24, 2019 06:26
Show Gist options
  • Save b-barry/699222a74ce434672aef65e30d62fca1 to your computer and use it in GitHub Desktop.
Save b-barry/699222a74ce434672aef65e30d62fca1 to your computer and use it in GitHub Desktop.
Next.js @elastic/eui
const withSass = require('@zeit/next-sass');
// Use sass to import @elastic/eui scss
// @import "~@elastic/eui/src/global_styling/index";
// @import "~@elastic/eui/src/components/index";
module.exports = withSass({
webpack(config, {isServer}) {
if (isServer) {
/**
* We have to force the bundling of @elastic/eui and react-ace
* as Gatsby, then all loaders below will match and avoid HTMLElement issues
*/
config.externals = config.externals.map(fn => {
return (context, request, callback) => {
if (request.indexOf('@elastic/eui') > -1 || request.indexOf('react-ace') > -1) {
return callback();
}
return fn(context, request, callback);
};
});
config.module.rules.push(
{
test: /react-ace/,
use: 'null-loader',
},
);
let definePluginId = config.plugins.findIndex(p => p.constructor.name === 'DefinePlugin');
config.plugins[definePluginId].definitions = {
...config.plugins[definePluginId].definitions,
HTMLElement: function(){},
window: function(){},
};
}
return config;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment