| 133 | |
| 134 | // Create the production build and print the deployment instructions. |
| 135 | function build(previousFileSizes) { |
| 136 | console.log('Creating an optimized production build...'); |
| 137 | |
| 138 | const compiler = webpack(config); |
| 139 | return new Promise((resolve, reject) => { |
| 140 | compiler.run((err, stats) => { |
| 141 | let messages; |
| 142 | if (err) { |
| 143 | if (!err.message) { |
| 144 | return reject(err); |
| 145 | } |
| 146 | |
| 147 | let errMessage = err.message; |
| 148 | |
| 149 | // Add additional information for postcss errors |
| 150 | if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) { |
| 151 | errMessage += |
| 152 | '\nCompileError: Begins at CSS selector ' + |
| 153 | err['postcssNode'].selector; |
| 154 | } |
| 155 | |
| 156 | messages = formatWebpackMessages({ |
| 157 | errors: [errMessage], |
| 158 | warnings: [], |
| 159 | }); |
| 160 | } else { |
| 161 | messages = formatWebpackMessages( |
| 162 | stats.toJson({ all: false, warnings: true, errors: true }) |
| 163 | ); |
| 164 | } |
| 165 | if (messages.errors.length) { |
| 166 | // Only keep the first error. Others are often indicative |
| 167 | // of the same problem, but confuse the reader with noise. |
| 168 | if (messages.errors.length > 1) { |
| 169 | messages.errors.length = 1; |
| 170 | } |
| 171 | return reject(new Error(messages.errors.join('\n\n'))); |
| 172 | } |
| 173 | if ( |
| 174 | process.env.CI && |
| 175 | (typeof process.env.CI !== 'string' || |
| 176 | process.env.CI.toLowerCase() !== 'false') && |
| 177 | messages.warnings.length |
| 178 | ) { |
| 179 | // Ignore sourcemap warnings in CI builds. See #8227 for more info. |
| 180 | const filteredWarnings = messages.warnings.filter( |
| 181 | w => !/Failed to parse source map/.test(w) |
| 182 | ); |
| 183 | if (filteredWarnings.length) { |
| 184 | console.log( |
| 185 | chalk.yellow( |
| 186 | '\nTreating warnings as errors because process.env.CI = true.\n' + |
| 187 | 'Most CI servers set it automatically.\n' |
| 188 | ) |
| 189 | ); |
| 190 | return reject(new Error(filteredWarnings.join('\n\n'))); |
| 191 | } |
| 192 | } |