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