@@ -28,6 +28,7 @@ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
28
28
const getCSSModuleLocalIdent = require ( 'react-dev-utils/getCSSModuleLocalIdent' ) ;
29
29
const paths = require ( './paths' ) ;
30
30
const modules = require ( './modules' ) ;
31
+ const yarnWorkspaces = require ( './yarn-workspaces' ) ;
31
32
const getClientEnvironment = require ( './env' ) ;
32
33
const ModuleNotFoundPlugin = require ( 'react-dev-utils/ModuleNotFoundPlugin' ) ;
33
34
const ForkTsCheckerWebpackPlugin = require ( 'react-dev-utils/ForkTsCheckerWebpackPlugin' ) ;
@@ -59,6 +60,8 @@ const cssModuleRegex = /\.module\.css$/;
59
60
const sassRegex = / \. ( s c s s | s a s s ) $ / ;
60
61
const sassModuleRegex = / \. m o d u l e \. ( s c s s | s a s s ) $ / ;
61
62
63
+ const workspacesConfig = yarnWorkspaces . init ( paths ) ;
64
+
62
65
// This is the production and development configuration.
63
66
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
64
67
module . exports = function ( webpackEnv ) {
@@ -69,6 +72,27 @@ module.exports = function(webpackEnv) {
69
72
// passed into alias object. Uses a flag if passed into the build command
70
73
const isEnvProductionProfile =
71
74
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 ;
72
96
73
97
// Webpack uses `publicPath` to determine where the app is being served from.
74
98
// It requires a trailing slash, or the file assets will get an incorrect path.
@@ -302,6 +326,7 @@ module.exports = function(webpackEnv) {
302
326
extensions : paths . moduleFileExtensions
303
327
. map ( ext => `.${ ext } ` )
304
328
. filter ( ext => useTypeScript || ! ext . includes ( 'ts' ) ) ,
329
+ mainFields,
305
330
alias : {
306
331
// Support React Native Web
307
332
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -378,7 +403,13 @@ module.exports = function(webpackEnv) {
378
403
loader : require . resolve ( 'eslint-loader' ) ,
379
404
} ,
380
405
] ,
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
+ / \. t s x ? / . test ( path . extname ( file ) ) &&
411
+ ! file . startsWith ( paths . appSrc )
412
+ : undefined ,
382
413
} ,
383
414
{
384
415
// "oneOf" will traverse all following loaders until one will
@@ -400,7 +431,7 @@ module.exports = function(webpackEnv) {
400
431
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
401
432
{
402
433
test : / \. ( j s | m j s | j s x | t s | t s x ) $ / ,
403
- include : paths . appSrc ,
434
+ include : includePaths ,
404
435
loader : require . resolve ( 'babel-loader' ) ,
405
436
options : {
406
437
customize : require . resolve (
@@ -698,6 +729,10 @@ module.exports = function(webpackEnv) {
698
729
typescript : resolve . sync ( 'typescript' , {
699
730
basedir : paths . appNodeModules ,
700
731
} ) ,
732
+ compilerOptions : {
733
+ skipLibCheck : true ,
734
+ suppressOutputPathCheck : true ,
735
+ } ,
701
736
async : isEnvDevelopment ,
702
737
useTypescriptIncrementalApi : true ,
703
738
checkSyntacticErrors : true ,
@@ -715,6 +750,7 @@ module.exports = function(webpackEnv) {
715
750
'!**/src/setupProxy.*' ,
716
751
'!**/src/setupTests.*' ,
717
752
] ,
753
+ watch : includePaths ,
718
754
silent : true ,
719
755
// The formatter is invoked directly in WebpackDevServerUtils during development
720
756
formatter : isEnvProduction ? typescriptFormatter : undefined ,
0 commit comments