@@ -28,6 +28,7 @@ const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2828const getCSSModuleLocalIdent = require ( 'react-dev-utils/getCSSModuleLocalIdent' ) ;
2929const paths = require ( './paths' ) ;
3030const modules = require ( './modules' ) ;
31+ const yarnWorkspaces = require ( './yarn-workspaces' ) ;
3132const getClientEnvironment = require ( './env' ) ;
3233const ModuleNotFoundPlugin = require ( 'react-dev-utils/ModuleNotFoundPlugin' ) ;
3334const ForkTsCheckerWebpackPlugin = require ( 'react-dev-utils/ForkTsCheckerWebpackPlugin' ) ;
@@ -59,6 +60,8 @@ const cssModuleRegex = /\.module\.css$/;
5960const sassRegex = / \. ( s c s s | s a s s ) $ / ;
6061const sassModuleRegex = / \. m o d u l e \. ( s c s s | s a s s ) $ / ;
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.
6467module . 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+ / \. t s x ? / . 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 : / \. ( j s | m j s | j s x | t s | t s x ) $ / ,
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