| 101 | |
| 102 | // Create the production build and print the deployment instructions. |
| 103 | function build(previousFileSizes) { |
| 104 | console.log('Creating an optimized production build...'); |
| 105 | |
| 106 | let compiler = webpack(config); |
| 107 | return new Promise((resolve, reject) => { |
| 108 | compiler.run((err, stats) => { |
| 109 | if (err) { |
| 110 | return reject(err); |
| 111 | } |
| 112 | const messages = formatWebpackMessages(stats.toJson({}, true)); |
| 113 | if (messages.errors.length) { |
| 114 | // Only keep the first error. Others are often indicative |
| 115 | // of the same problem, but confuse the reader with noise. |
| 116 | if (messages.errors.length > 1) { |
| 117 | messages.errors.length = 1; |
| 118 | } |
| 119 | return reject(new Error(messages.errors.join('\n\n'))); |
| 120 | } |
| 121 | if ( |
| 122 | process.env.CI && |
| 123 | (typeof process.env.CI !== 'string' || |
| 124 | process.env.CI.toLowerCase() !== 'false') && |
| 125 | messages.warnings.length |
| 126 | ) { |
| 127 | console.log( |
| 128 | chalk.yellow( |
| 129 | '\nTreating warnings as errors because process.env.CI = true.\n' + |
| 130 | 'Most CI servers set it automatically.\n' |
| 131 | ) |
| 132 | ); |
| 133 | return reject(new Error(messages.warnings.join('\n\n'))); |
| 134 | } |
| 135 | return resolve({ |
| 136 | stats, |
| 137 | previousFileSizes, |
| 138 | warnings: messages.warnings, |
| 139 | }); |
| 140 | }); |
| 141 | }); |
| 142 | } |
| 143 | |
| 144 | function copyPublicFolder() { |
| 145 | fs.copySync(paths.appPublic, paths.appBuild, { |