Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

fix(devenv): patch WebPack entry config #47

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,33 @@ exports.createPages = ({ actions, graphql }) => {
});
};

exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
exports.onCreateWebpackConfig = ({ actions, getConfig, stage }) => {
const config = getConfig();
const { module } = config;
const { entry, module } = config;
const { rules } = module;
const { commons } = entry || {};
const appIndex = !commons ? -1 : commons.findIndex(item => /app$/i.test(item));
actions.replaceWebpackConfig({
...config,
entry: stage !== 'develop' || appIndex < 0 ? entry : {
...entry,
commons: [
// Ensure loading polyfills before RHL loads `react` module
// This prevents a condition where `Symbol` polyfill loaded
// after `react` is loaded and before `react-dom` is loaded
// which makes `react` and `react-dom` refer to different `Symbol` definitions.
//
// Refs:
// https://github.com/gatsbyjs/gatsby/issues/7003
// https://github.com/facebook/react/issues/8379#issuecomment-263962787
//
// The problem seems to happen only in development environment (see below link)
// and thus we patch `entry` WebPack config only for development environment.
// https://github.com/carbon-design-system/carbon-website-gatsby/issues/24#issuecomment-421593414
path.resolve(__dirname, 'src/polyfills/index.js'),
...commons,
],
},
module: {
...module,
rules: [
Expand Down
1 change: 1 addition & 0 deletions src/polyfills/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'core-js/modules/es7.object.values';
import 'core-js/modules/es6.promise.js';
import 'core-js/modules/es6.string.includes';
import 'core-js/modules/es6.string.trim';
import 'core-js/modules/es6.symbol';
/* eslint-enable import/no-extraneous-dependencies */

import './custom-event';
Expand Down