in next.config.js [65:111]
webpack(config, { isServer }) {
// EUI uses some libraries and features that don't work outside of a
// browser by default. We need to configure the build so that these
// features are either ignored or replaced with stub implementations.
if (isServer) {
config.externals = config.externals.map(eachExternal => {
if (typeof eachExternal !== 'function') {
return eachExternal;
}
return (context, callback) => {
if (context.request.indexOf('@elastic/eui') > -1) {
return callback();
}
return eachExternal(context, callback);
};
});
// Mock HTMLElement on the server-side
const definePluginId = config.plugins.findIndex(
p => p.constructor.name === 'DefinePlugin'
);
config.plugins[definePluginId].definitions = {
...config.plugins[definePluginId].definitions,
HTMLElement: function () {},
};
}
// Copy theme CSS files into `public`
config.plugins.push(
new CopyWebpackPlugin({ patterns: themeConfig.copyConfig }),
// Moment ships with a large number of locales. Exclude them, leaving
// just the default English locale. If you need other locales, see:
// https://create-react-app.dev/docs/troubleshooting/#momentjs-locales-are-missing
new IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
})
);
config.resolve.mainFields = ['module', 'main'];
return config;
},