@@ -77,100 +77,119 @@ const spaHtmlPaths = Object.entries(spaPaths).reduce((acc, [key, value]) => {
77
77
return acc ;
78
78
} , { } ) ;
79
79
80
- const staticPath = path . join ( paths . appSrc , 'scripts' , 'index.js' ) ;
81
-
82
- // Generate configuration
83
- const config = [
84
- configFactory ( 'production' , {
85
- entries : {
86
- app : path . join ( paths . appSrc , 'index.js' ) ,
87
- ...( fs . existsSync ( staticPath ) && { static : staticPath } ) ,
88
- ...getEntries ( 'lib' , paths . libDir , '/*.{js,scss,css}' ) ,
89
- ...spaEntries ,
90
- } ,
91
- spaHtmlPaths,
92
- } ) ,
93
- configFactory ( 'lib' , {
94
- entries : {
95
- ...getEntries ( 'components' , paths . componentsDir , '/*.{js,scss,css}' ) ,
96
- ...getEntries ( 'components' , paths . componentsDir , '/**/index.js' ) ,
97
- ...getEntries ( 'components' , paths . componentsDir , '/**/*.static.js' ) ,
98
- } ,
99
- } ) ,
100
- ] ;
101
-
102
- // We require that you explicitly set browsers and do not fall back to
103
- // browserslist defaults.
104
- const { checkBrowsers } = require ( 'react-dev-utils/browsersHelper' ) ;
105
- checkBrowsers ( paths . appPath , isInteractive )
106
- . then ( ( ) => {
107
- // First, read the current file sizes in build directory.
108
- // This lets us display how much they changed later.
109
- return measureFileSizesBeforeBuild ( paths . appBuild ) ;
110
- } )
111
- . then ( previousFileSizes => {
112
- // Remove all content but keep the directory so that
113
- // if you're in it, you don't end up in Trash
114
- fs . emptyDirSync ( paths . appBuild ) ;
115
- // Merge with the public folder
116
- copyPublicFolder ( ) ;
117
- // Start the webpack build
118
- return build ( previousFileSizes ) ;
119
- } )
120
- . then (
121
- ( { stats, previousFileSizes, warnings } ) => {
122
- if ( warnings . length ) {
123
- console . log ( chalk . yellow ( 'Compiled with warnings.\n' ) ) ;
124
- console . log ( warnings . join ( '\n\n' ) ) ;
125
- console . log (
126
- '\nSearch for the ' +
127
- chalk . underline ( chalk . yellow ( 'keywords' ) ) +
128
- ' to learn more about each warning.'
129
- ) ;
130
- console . log (
131
- 'To ignore, add ' +
132
- chalk . cyan ( '// eslint-disable-next-line' ) +
133
- ' to the line before.\n'
134
- ) ;
135
- } else {
136
- console . log ( chalk . green ( 'Compiled successfully.\n' ) ) ;
80
+ const appConfig = configFactory ( 'production' , {
81
+ entries : {
82
+ app : paths . appIndexJs ,
83
+ ...( fs . existsSync ( paths . staticJs ) && { static : paths . staticJs } ) ,
84
+ ...getEntries ( 'lib' , paths . libDir , '/*.{js,jsx,ts,tsx,scss,css}' ) ,
85
+ ...spaEntries ,
86
+ } ,
87
+ spaHtmlPaths,
88
+ } ) ;
89
+
90
+ const componentsConfig = configFactory ( 'lib' , {
91
+ entries : {
92
+ ...getEntries (
93
+ 'components' ,
94
+ paths . componentsDir ,
95
+ '/*.{js,jsx,ts,tsx,scss,css}'
96
+ ) ,
97
+ ...getEntries (
98
+ 'components' ,
99
+ paths . componentsDir ,
100
+ '/**/index.{js,jsx,ts,tsx}'
101
+ ) ,
102
+ ...getEntries (
103
+ 'components' ,
104
+ paths . componentsDir ,
105
+ '/**/*.static.{js,jsx,ts,tsx}'
106
+ ) ,
107
+ } ,
108
+ } ) ;
109
+
110
+ const run = async ( ) => {
111
+ await runBuild ( appConfig , 'app' ) ;
112
+ await runBuild ( componentsConfig , 'components' ) ;
113
+ } ;
114
+
115
+ run ( ) ;
116
+
117
+ async function runBuild ( config , buildType ) {
118
+ // We require that you explicitly set browsers and do not fall back to
119
+ // browserslist defaults.
120
+ const { checkBrowsers } = require ( 'react-dev-utils/browsersHelper' ) ;
121
+ return checkBrowsers ( paths . appPath , isInteractive )
122
+ . then ( ( ) => {
123
+ // First, read the current file sizes in build directory.
124
+ // This lets us display how much they changed later.
125
+ return measureFileSizesBeforeBuild ( paths . appBuild ) ;
126
+ } )
127
+ . then ( previousFileSizes => {
128
+ if ( buildType === 'app' ) {
129
+ // Remove all content but keep the directory so that
130
+ // if you're in it, you don't end up in Trash
131
+ fs . emptyDirSync ( paths . appBuild ) ;
132
+ // Merge with the public folder
133
+ copyPublicFolder ( ) ;
137
134
}
135
+ // Start the webpack build
136
+ return build ( previousFileSizes , config , buildType ) ;
137
+ } )
138
+ . then (
139
+ ( { stats, previousFileSizes, warnings } ) => {
140
+ if ( warnings . length ) {
141
+ console . log ( chalk . yellow ( `Compiled ${ buildType } with warnings.\n` ) ) ;
142
+ console . log ( warnings . join ( '\n\n' ) ) ;
143
+ console . log (
144
+ '\nSearch for the ' +
145
+ chalk . underline ( chalk . yellow ( 'keywords' ) ) +
146
+ ' to learn more about each warning.'
147
+ ) ;
148
+ console . log (
149
+ 'To ignore, add ' +
150
+ chalk . cyan ( '// eslint-disable-next-line' ) +
151
+ ' to the line before.\n'
152
+ ) ;
153
+ } else {
154
+ console . log ( chalk . green ( `Compiled ${ buildType } successfully.\n` ) ) ;
155
+ }
138
156
139
- console . log ( 'File sizes after gzip:\n' ) ;
140
- printFileSizesAfterBuild (
141
- stats ,
142
- previousFileSizes ,
143
- paths . appBuild ,
144
- WARN_AFTER_BUNDLE_GZIP_SIZE ,
145
- WARN_AFTER_CHUNK_GZIP_SIZE
146
- ) ;
147
- console . log ( ) ;
148
- } ,
149
- err => {
150
- const tscCompileOnError = process . env . TSC_COMPILE_ON_ERROR === 'true' ;
151
- if ( tscCompileOnError ) {
152
- console . log (
153
- chalk . yellow (
154
- 'Compiled with the following type errors (you may want to check these before deploying your app):\n'
155
- )
157
+ console . log ( 'File sizes after gzip:\n' ) ;
158
+ printFileSizesAfterBuild (
159
+ stats ,
160
+ previousFileSizes ,
161
+ paths . appBuild ,
162
+ WARN_AFTER_BUNDLE_GZIP_SIZE ,
163
+ WARN_AFTER_CHUNK_GZIP_SIZE
156
164
) ;
157
- printBuildError ( err ) ;
158
- } else {
159
- console . log ( chalk . red ( 'Failed to compile.\n' ) ) ;
160
- printBuildError ( err ) ;
161
- process . exit ( 1 ) ;
165
+ console . log ( ) ;
166
+ } ,
167
+ err => {
168
+ const tscCompileOnError = process . env . TSC_COMPILE_ON_ERROR === 'true' ;
169
+ if ( tscCompileOnError ) {
170
+ console . log (
171
+ chalk . yellow (
172
+ 'Compiled with the following buildType errors (you may want to check these before deploying your app):\n'
173
+ )
174
+ ) ;
175
+ printBuildError ( err ) ;
176
+ } else {
177
+ console . log ( chalk . red ( 'Failed to compile.\n' ) ) ;
178
+ printBuildError ( err ) ;
179
+ process . exit ( 1 ) ;
180
+ }
162
181
}
163
- }
164
- )
165
- . catch ( err => {
166
- if ( err && err . message ) {
167
- console . log ( err . message ) ;
168
- }
169
- process . exit ( 1 ) ;
170
- } ) ;
182
+ )
183
+ . catch ( err => {
184
+ if ( err && err . message ) {
185
+ console . log ( err . message ) ;
186
+ }
187
+ process . exit ( 1 ) ;
188
+ } ) ;
189
+ }
171
190
172
191
// Create the production build and print the deployment instructions.
173
- function build ( previousFileSizes ) {
192
+ function build ( previousFileSizes , config , buildType ) {
174
193
// We used to support resolving modules according to `NODE_PATH`.
175
194
// This now has been deprecated in favor of jsconfig/tsconfig.json
176
195
// This lets you use absolute paths in imports inside large monorepos:
@@ -183,7 +202,7 @@ function build(previousFileSizes) {
183
202
console . log ( ) ;
184
203
}
185
204
186
- console . log ( ' Creating an optimized production build...' ) ;
205
+ console . log ( ` Creating an optimized production build of ${ buildType } ...` ) ;
187
206
188
207
const compiler = webpack ( config ) ;
189
208
return new Promise ( ( resolve , reject ) => {
0 commit comments