Skip to content

Commit a498a36

Browse files
authored
Merge branch 'master' into v3.3.0-alpha-08-ts
2 parents 9a817dd + c236cdd commit a498a36

File tree

7 files changed

+348
-8
lines changed

7 files changed

+348
-8
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# :warning: WARNING!
2+
3+
This is a custom scripts-version of React-Scripts that provides Monorepo support.
4+
5+
See [React Workspaces Playground](https://github.com/react-workspaces/react-workspaces-playground) for a working demo.
6+
7+
[![React Workspaces Playground Screenshots](https://i.imgur.com/7snWXD0.png)](https://github.com/react-workspaces/react-workspaces-playground)
8+
9+
For more information on why this was created, please read this for more info: [Support Lerna and/or Yarn Workspaces #1333](https://github.com/facebook/create-react-app/issues/1333)
10+
111
# Create React App [![Build Status](https://dev.azure.com/facebook/create-react-app/_apis/build/status/facebook.create-react-app?branchName=master)](https://dev.azure.com/facebook/create-react-app/_build/latest?definitionId=1&branchName=master) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg)](https://github.com/facebook/create-react-app/blob/master/CONTRIBUTING.md)
212

313
Create React apps with no build configuration.

packages/react-scripts/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# :warning: WARNING!
2+
3+
This is a custom scripts-version of React-Scripts that provides Monorepo support.
4+
5+
See [React Workspaces Playground](https://github.com/react-workspaces/react-workspaces-playground) for a working demo.
6+
7+
[![React Workspaces Playground Screenshots](https://i.imgur.com/7snWXD0.png)](https://github.com/react-workspaces/react-workspaces-playground)
8+
9+
For more information on why this ways created, please read this for more info: https://github.com/F1LT3R/cra-workspaces-support-1333
10+
111
# react-scripts
212

313
This package includes scripts and configuration used by [Create React App](https://github.com/facebook/create-react-app).<br>

packages/react-scripts/config/paths.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const path = require('path');
1212
const fs = require('fs');
1313
const url = require('url');
14+
const findUp = require('find-up');
1415

1516
// Make sure any symlinks in the project folder are resolved:
1617
// https://github.com/facebook/create-react-app/issues/637
@@ -122,7 +123,9 @@ module.exports = {
122123
};
123124

124125
const ownPackageJson = require('../package.json');
125-
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
126+
const reactScriptsPath = findUp.sync(`node_modules/${ownPackageJson.name}`, {
127+
cwd: resolveApp('.'),
128+
});
126129
const reactScriptsLinked =
127130
fs.existsSync(reactScriptsPath) &&
128131
fs.lstatSync(reactScriptsPath).isSymbolicLink();

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2828
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
2929
const paths = require('./paths');
3030
const modules = require('./modules');
31+
const yarnWorkspaces = require('./yarn-workspaces');
3132
const getClientEnvironment = require('./env');
3233
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3334
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
@@ -59,6 +60,8 @@ const cssModuleRegex = /\.module\.css$/;
5960
const sassRegex = /\.(scss|sass)$/;
6061
const sassModuleRegex = /\.module\.(scss|sass)$/;
6162

63+
const workspacesConfig = yarnWorkspaces.init(paths);
64+
6265
// This is the production and development configuration.
6366
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
6467
module.exports = function(webpackEnv) {
@@ -69,6 +72,27 @@ module.exports = function(webpackEnv) {
6972
// passed into alias object. Uses a flag if passed into the build command
7073
const isEnvProductionProfile =
7174
isEnvProduction && process.argv.includes('--profile');
75+
76+
const workspacesMainFields = [
77+
workspacesConfig.packageEntry,
78+
'browser',
79+
'module',
80+
'main',
81+
];
82+
83+
const mainFields =
84+
isEnvDevelopment && workspacesConfig.development
85+
? workspacesMainFields
86+
: isEnvProduction && workspacesConfig.production
87+
? workspacesMainFields
88+
: undefined;
89+
90+
const includePaths =
91+
isEnvDevelopment && workspacesConfig.development
92+
? [paths.appSrc, ...workspacesConfig.paths]
93+
: isEnvProduction && workspacesConfig.production
94+
? [paths.appSrc, ...workspacesConfig.paths]
95+
: paths.appSrc;
7296

7397
// Webpack uses `publicPath` to determine where the app is being served from.
7498
// It requires a trailing slash, or the file assets will get an incorrect path.
@@ -302,6 +326,7 @@ module.exports = function(webpackEnv) {
302326
extensions: paths.moduleFileExtensions
303327
.map(ext => `.${ext}`)
304328
.filter(ext => useTypeScript || !ext.includes('ts')),
329+
mainFields,
305330
alias: {
306331
// Support React Native Web
307332
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -378,7 +403,13 @@ module.exports = function(webpackEnv) {
378403
loader: require.resolve('eslint-loader'),
379404
},
380405
],
381-
include: paths.appSrc,
406+
include: includePaths,
407+
// Don't lint typescript files outside the main package because it has problems with some syntax rules, e.g. abstract
408+
exclude: useTypeScript
409+
? file =>
410+
/\.tsx?/.test(path.extname(file)) &&
411+
!file.startsWith(paths.appSrc)
412+
: undefined,
382413
},
383414
{
384415
// "oneOf" will traverse all following loaders until one will
@@ -400,7 +431,7 @@ module.exports = function(webpackEnv) {
400431
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
401432
{
402433
test: /\.(js|mjs|jsx|ts|tsx)$/,
403-
include: paths.appSrc,
434+
include: includePaths,
404435
loader: require.resolve('babel-loader'),
405436
options: {
406437
customize: require.resolve(
@@ -698,6 +729,10 @@ module.exports = function(webpackEnv) {
698729
typescript: resolve.sync('typescript', {
699730
basedir: paths.appNodeModules,
700731
}),
732+
compilerOptions: {
733+
skipLibCheck: true,
734+
suppressOutputPathCheck: true,
735+
},
701736
async: isEnvDevelopment,
702737
useTypescriptIncrementalApi: true,
703738
checkSyntacticErrors: true,
@@ -715,6 +750,7 @@ module.exports = function(webpackEnv) {
715750
'!**/src/setupProxy.*',
716751
'!**/src/setupTests.*',
717752
],
753+
watch: includePaths,
718754
silent: true,
719755
// The formatter is invoked directly in WebpackDevServerUtils during development
720756
formatter: isEnvProduction ? typescriptFormatter : undefined,

0 commit comments

Comments
 (0)