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