6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
// @remove -on-eject-end
9
- 'use strict' ;
9
+ 'use strict'
10
10
11
11
// Do this as the first thing so that any code reading it knows the right env.
12
- process . env . BABEL_ENV = 'production' ;
13
- process . env . NODE_ENV = 'production' ;
12
+ process . env . BABEL_ENV = 'production'
13
+ process . env . NODE_ENV = 'production'
14
14
15
15
// Makes the script crash on unhandled rejections instead of silently
16
16
// ignoring them. In the future, promise rejections that are not handled will
17
17
// terminate the Node.js process with a non-zero exit code.
18
18
process . on ( 'unhandledRejection' , err => {
19
- throw err ;
20
- } ) ;
19
+ throw err
20
+ } )
21
21
22
22
// Ensure environment variables are read.
23
- require ( '../config/env' ) ;
24
-
25
- const path = require ( 'path' ) ;
26
- const chalk = require ( 'react-dev-utils/chalk' ) ;
27
- const fs = require ( 'fs-extra' ) ;
28
- const bfj = require ( 'bfj' ) ;
29
- const webpack = require ( 'webpack' ) ;
30
- const configFactory = require ( '../config/webpack.config' ) ;
31
- const paths = require ( '../config/paths' ) ;
32
- const checkRequiredFiles = require ( 'react-dev-utils/checkRequiredFiles' ) ;
33
- const formatWebpackMessages = require ( 'react-dev-utils/formatWebpackMessages' ) ;
34
- const printHostingInstructions = require ( 'react-dev-utils/printHostingInstructions' ) ;
35
- const FileSizeReporter = require ( 'react-dev-utils/FileSizeReporter' ) ;
36
- const printBuildError = require ( 'react-dev-utils/printBuildError' ) ;
23
+ require ( '../config/env' )
24
+
25
+ const path = require ( 'path' )
26
+ const chalk = require ( 'react-dev-utils/chalk' )
27
+ const fs = require ( 'fs-extra' )
28
+ const bfj = require ( 'bfj' )
29
+ const webpack = require ( 'webpack' )
30
+ const configFactory = require ( '../config/webpack.config' )
31
+ const paths = require ( '../config/paths' )
32
+ const checkRequiredFiles = require ( 'react-dev-utils/checkRequiredFiles' )
33
+ const formatWebpackMessages = require ( 'react-dev-utils/formatWebpackMessages' )
34
+ const printHostingInstructions = require ( 'react-dev-utils/printHostingInstructions' )
35
+ const FileSizeReporter = require ( 'react-dev-utils/FileSizeReporter' )
36
+ const printBuildError = require ( 'react-dev-utils/printBuildError' )
37
37
// frontier
38
38
// coalesce per-locale locales for speedier intl perf scaling
39
- const { coalesceLocales } = require ( './coalesceLocales' ) ;
39
+ const { coalesceLocales } = require ( './coalesceLocales' )
40
40
// /frontier
41
41
42
- const measureFileSizesBeforeBuild = FileSizeReporter . measureFileSizesBeforeBuild ;
43
- const printFileSizesAfterBuild = FileSizeReporter . printFileSizesAfterBuild ;
44
- const useYarn = fs . existsSync ( paths . yarnLockFile ) ;
42
+ const measureFileSizesBeforeBuild = FileSizeReporter . measureFileSizesBeforeBuild
43
+ const printFileSizesAfterBuild = FileSizeReporter . printFileSizesAfterBuild
44
+ const useYarn = fs . existsSync ( paths . yarnLockFile )
45
45
46
46
// These sizes are pretty large. We'll warn for bundles exceeding them.
47
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024 ;
48
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024 ;
47
+ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024
48
+ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024
49
49
50
- const isInteractive = process . stdout . isTTY ;
50
+ const isInteractive = process . stdout . isTTY
51
51
52
52
// Warn and crash if required files are missing
53
53
if ( ! checkRequiredFiles ( [ paths . appHtml , paths . appIndexJs ] ) ) {
54
- process . exit ( 1 ) ;
54
+ process . exit ( 1 )
55
55
}
56
56
57
- const argv = process . argv . slice ( 2 ) ;
58
- const writeStatsJson = argv . indexOf ( '--stats' ) !== - 1 ;
57
+ const argv = process . argv . slice ( 2 )
58
+ const writeStatsJson = argv . indexOf ( '--stats' ) !== - 1
59
59
60
60
// Generate configuration
61
- const config = configFactory ( 'production' ) ;
61
+ const config = configFactory ( 'production' )
62
62
63
63
// We require that you explicitly set browsers and do not fall back to
64
64
// browserslist defaults.
65
- const { checkBrowsers } = require ( 'react-dev-utils/browsersHelper' ) ;
65
+ const { checkBrowsers } = require ( 'react-dev-utils/browsersHelper' )
66
66
checkBrowsers ( paths . appPath , isInteractive )
67
67
. then ( ( ) => {
68
68
// First, read the current file sizes in build directory.
69
69
// This lets us display how much they changed later.
70
- return measureFileSizesBeforeBuild ( paths . appBuild ) ;
70
+ return measureFileSizesBeforeBuild ( paths . appBuild )
71
71
} )
72
72
. then ( previousFileSizes => {
73
73
// Remove all content but keep the directory so that
74
74
// if you're in it, you don't end up in Trash
75
- fs . emptyDirSync ( paths . appBuild ) ;
75
+ fs . emptyDirSync ( paths . appBuild )
76
76
// Merge with the public folder
77
- copyPublicFolder ( ) ;
77
+ copyPublicFolder ( )
78
78
// Start the webpack build
79
- return build ( previousFileSizes ) ;
79
+ return build ( previousFileSizes )
80
80
} )
81
81
. then (
82
82
( { stats, previousFileSizes, warnings } ) => {
83
83
if ( warnings . length ) {
84
- console . log ( chalk . yellow ( 'Compiled with warnings.\n' ) ) ;
85
- console . log ( warnings . join ( '\n\n' ) ) ;
84
+ console . log ( chalk . yellow ( 'Compiled with warnings.\n' ) )
85
+ console . log ( warnings . join ( '\n\n' ) )
86
86
console . log (
87
- '\nSearch for the ' +
88
- chalk . underline ( chalk . yellow ( 'keywords' ) ) +
89
- ' to learn more about each warning.'
90
- ) ;
91
- console . log (
92
- 'To ignore, add ' + chalk . cyan ( '// eslint-disable-next-line' ) + ' to the line before.\n'
93
- ) ;
87
+ '\nSearch for the ' + chalk . underline ( chalk . yellow ( 'keywords' ) ) + ' to learn more about each warning.'
88
+ )
89
+ console . log ( 'To ignore, add ' + chalk . cyan ( '// eslint-disable-next-line' ) + ' to the line before.\n' )
94
90
} else {
95
- console . log ( chalk . green ( 'Compiled successfully.\n' ) ) ;
91
+ console . log ( chalk . green ( 'Compiled successfully.\n' ) )
96
92
}
97
93
98
- console . log ( 'File sizes after gzip:\n' ) ;
94
+ console . log ( 'File sizes after gzip:\n' )
99
95
printFileSizesAfterBuild (
100
96
stats ,
101
97
previousFileSizes ,
102
98
paths . appBuild ,
103
99
WARN_AFTER_BUNDLE_GZIP_SIZE ,
104
100
WARN_AFTER_CHUNK_GZIP_SIZE
105
- ) ;
106
- console . log ( ) ;
107
-
108
- const appPackage = require ( paths . appPackageJson ) ;
109
- const publicUrl = paths . publicUrlOrPath ;
110
- const publicPath = config . output . publicPath ;
111
- const buildFolder = path . relative ( process . cwd ( ) , paths . appBuild ) ;
112
- printHostingInstructions ( appPackage , publicUrl , publicPath , buildFolder , useYarn ) ;
101
+ )
102
+ console . log ( )
103
+
104
+ const appPackage = require ( paths . appPackageJson )
105
+ const publicUrl = paths . publicUrlOrPath
106
+ const publicPath = config . output . publicPath
107
+ const buildFolder = path . relative ( process . cwd ( ) , paths . appBuild )
108
+ printHostingInstructions ( appPackage , publicUrl , publicPath , buildFolder , useYarn )
113
109
} ,
114
110
err => {
115
- const tscCompileOnError = process . env . TSC_COMPILE_ON_ERROR === 'true' ;
111
+ const tscCompileOnError = process . env . TSC_COMPILE_ON_ERROR === 'true'
116
112
if ( tscCompileOnError ) {
117
113
console . log (
118
114
chalk . yellow (
119
115
'Compiled with the following type errors (you may want to check these before deploying your app):\n'
120
116
)
121
- ) ;
122
- printBuildError ( err ) ;
117
+ )
118
+ printBuildError ( err )
123
119
} else {
124
- console . log ( chalk . red ( 'Failed to compile.\n' ) ) ;
125
- printBuildError ( err ) ;
126
- process . exit ( 1 ) ;
120
+ console . log ( chalk . red ( 'Failed to compile.\n' ) )
121
+ printBuildError ( err )
122
+ process . exit ( 1 )
127
123
}
128
124
}
129
125
)
130
126
. catch ( err => {
131
127
if ( err && err . message ) {
132
- console . log ( err . message ) ;
128
+ console . log ( err . message )
133
129
}
134
- process . exit ( 1 ) ;
135
- } ) ;
130
+ process . exit ( 1 )
131
+ } )
136
132
137
133
// Create the production build and print the deployment instructions.
138
134
function build ( previousFileSizes ) {
139
- console . log ( 'Creating an optimized production build...' ) ;
135
+ console . log ( 'Creating an optimized production build...' )
140
136
141
- const compiler = webpack ( config ) ;
137
+ const compiler = webpack ( config )
142
138
return new Promise ( ( resolve , reject ) => {
143
139
// frontier
144
140
// coalesce per-locale locales for speedier intl perf scaling
145
141
compiler . hooks . beforeRun . tap ( 'perlocale' , ( ) => {
146
- coalesceLocales ( paths ) ;
147
- } ) ;
142
+ coalesceLocales ( paths )
143
+ } )
144
+
145
+ // UNCOMMENT FOR MORE DETAILS OF THE ERRORS IN A BUILD
146
+ // compiler.hooks.afterCompile.tap('afterCompile', compilation => {
147
+ // if (compilation.errors && compilation.errors.length > 0) {
148
+ // console.log(
149
+ // chalk.red(
150
+ // 'Errors occurred during compilation. Try to resolve the problems, and reach out to the Frontier Core team if you need help:\n'
151
+ // ),
152
+ // compilation.errors
153
+ // )
154
+ // }
155
+ // })
156
+
148
157
// /frontier
149
158
compiler . run ( ( err , stats ) => {
150
- let messages ;
159
+ let messages
151
160
if ( err ) {
152
161
if ( ! err . message ) {
153
- return reject ( err ) ;
162
+ return reject ( err )
154
163
}
155
164
156
- let errMessage = err . message ;
165
+ let errMessage = err . message
157
166
158
167
// Add additional information for postcss errors
159
168
if ( Object . prototype . hasOwnProperty . call ( err , 'postcssNode' ) ) {
160
- errMessage +=
161
- '\nCompileError: Begins at CSS selector ' +
162
- err [ 'postcssNode' ] . selector ;
169
+ errMessage += '\nCompileError: Begins at CSS selector ' + err [ 'postcssNode' ] . selector
163
170
}
164
171
165
172
messages = formatWebpackMessages ( {
166
173
errors : [ errMessage ] ,
167
174
warnings : [ ] ,
168
- } ) ;
175
+ } )
169
176
} else {
170
- messages = formatWebpackMessages (
171
- stats . toJson ( { all : false , warnings : true , errors : true } )
172
- ) ;
177
+ messages = formatWebpackMessages ( stats . toJson ( { all : false , warnings : true , errors : true } ) )
173
178
}
174
179
if ( messages . errors . length ) {
175
180
// Only keep the first error. Others are often indicative
176
181
// of the same problem, but confuse the reader with noise.
177
182
if ( messages . errors . length > 1 ) {
178
- messages . errors . length = 1 ;
183
+ messages . errors . length = 1
179
184
}
180
- return reject ( new Error ( messages . errors . join ( '\n\n' ) ) ) ;
185
+ return reject ( new Error ( messages . errors . join ( '\n\n' ) ) )
181
186
}
182
187
if (
183
188
process . env . CI &&
@@ -188,39 +193,39 @@ function build(previousFileSizes) {
188
193
// Frontier Ignore eslint warnings as well
189
194
const filteredWarnings = messages . warnings . filter (
190
195
w => ! / F a i l e d t o p a r s e s o u r c e m a p / . test ( w ) && ! / \[ e s l i n t \] / . test ( w )
191
- ) ;
196
+ )
192
197
if ( filteredWarnings . length ) {
193
198
console . log (
194
199
chalk . yellow (
195
200
'\nTreating warnings as errors because process.env.CI = true.\n' +
196
201
'Most CI servers set it automatically.\n'
197
202
)
198
- ) ;
199
- return reject ( new Error ( filteredWarnings . join ( '\n\n' ) ) ) ;
203
+ )
204
+ return reject ( new Error ( filteredWarnings . join ( '\n\n' ) ) )
200
205
}
201
206
}
202
207
203
208
const resolveArgs = {
204
209
stats,
205
210
previousFileSizes,
206
211
warnings : messages . warnings ,
207
- } ;
212
+ }
208
213
209
214
if ( writeStatsJson ) {
210
215
return bfj
211
216
. write ( paths . appBuild + '/bundle-stats.json' , stats . toJson ( ) )
212
217
. then ( ( ) => resolve ( resolveArgs ) )
213
- . catch ( error => reject ( new Error ( error ) ) ) ;
218
+ . catch ( error => reject ( new Error ( error ) ) )
214
219
}
215
220
216
- return resolve ( resolveArgs ) ;
217
- } ) ;
218
- } ) ;
221
+ return resolve ( resolveArgs )
222
+ } )
223
+ } )
219
224
}
220
225
221
226
function copyPublicFolder ( ) {
222
227
fs . copySync ( paths . appPublic , paths . appBuild , {
223
228
dereference : true ,
224
229
filter : file => file !== paths . appHtml ,
225
- } ) ;
230
+ } )
226
231
}
0 commit comments