| 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 | return reject(new Error(messages.errors.join('\n\n'))); |
| 115 | } |
| 116 | if ( |
| 117 | process.env.CI && |
| 118 | (typeof process.env.CI !== 'string' || |
| 119 | process.env.CI.toLowerCase() !== 'false') && |
| 120 | messages.warnings.length |
| 121 | ) { |
| 122 | console.log( |
| 123 | chalk.yellow( |
| 124 | '\nTreating warnings as errors because process.env.CI = true.\n' + |
| 125 | 'Most CI servers set it automatically.\n' |
| 126 | ) |
| 127 | ); |
| 128 | return reject(new Error(messages.warnings.join('\n\n'))); |
| 129 | } |
| 130 | return resolve({ |
| 131 | stats, |
| 132 | previousFileSizes, |
| 133 | warnings: messages.warnings, |
| 134 | }); |
| 135 | }); |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | function copyPublicFolder() { |
| 140 | fs.copySync(paths.appPublic, paths.appBuild, { |