Skip to content

Instantly share code, notes, and snippets.

@ScreamZ
Last active February 27, 2020 07:23
Show Gist options
  • Save ScreamZ/31bdb5c275749a1b9e75b4ae29395e49 to your computer and use it in GitHub Desktop.
Save ScreamZ/31bdb5c275749a1b9e75b4ae29395e49 to your computer and use it in GitHub Desktop.
// Import here to bypass non-SSR issues with EUI
@import "~@elastic/eui/src/theme_light.scss";
// …Some others imports before
const withSass = require("@zeit/next-sass");
const nextConfig = {
webpack(config, { isServer }) {
// Allows to prevent crashes on server with EUi
if (isServer) {
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);
};
});
// Mock react-ace server-side
config.module.rules.push({
test: /react-ace/,
use: "null-loader",
});
// Mock HTMLElement and window server-side
let definePluginId = config.plugins.findIndex(p => p.constructor.name === "DefinePlugin");
config.plugins[definePluginId].definitions = {
...config.plugins[definePluginId].definitions,
HTMLElement: function() {},
window: function() {},
};
}
return config;
}
module.exports = withSass(nextConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment