Skip to content

Commit dba6ddc

Browse files
committed
detect local components before setting alias
1 parent d44df39 commit dba6ddc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const paths = require('../../config/paths');
4+
5+
/**
6+
* Checking for loadable install, as there is need to set aliases when this is the case
7+
*/
8+
const isLocalComponents = () => {
9+
// Ensure `ssrEnabled` is on
10+
const appPackageJson = require(paths.appPackageJson);
11+
const isLocalComponentsInstalled =
12+
appPackageJson['@skyscanner-internal/local-components'] || {};
13+
14+
return isLocalComponentsInstalled;
15+
};
16+
17+
module.exports = isLocalComponents;

packages/react-scripts/config/webpack.config.ssr.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'
3434
const createEnvironmentHash = require('./webpack/persistentCache/createEnvironmentHash');
3535

3636
const isSsr = require('../backpack-addons/ssr/isSsr'); // #backpack-addons ssr
37+
const isLoadable = require('../backpack-addons/ssr/isLocalComponents'); // #backpack-addons ssr
3738

3839
// Just for the case that `ssr.js` exists in `src` folder but not in SSR mode
3940
const needBuildSsr = !isSsr() && fs.existsSync(paths.appSsrJs);
@@ -351,7 +352,9 @@ module.exports = function (webpackEnv) {
351352
.map(ext => `.${ext}`)
352353
.filter(ext => useTypeScript || !ext.includes('ts')),
353354
alias: {
354-
'@loadable/component': require.resolve('@loadable/component'),
355+
...(isLoadable()
356+
? { '@loadable/component': require.resolve('@loadable/component') }
357+
: {}),
355358
// Support React Native Web
356359
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
357360
'react-native': 'react-native-web',

0 commit comments

Comments
 (0)