UNPKG

@traildeer/sharetribe-scripts

Version:

Fork of facebookincubator/create-react-app@4.0.0 with some additional features.

143 lines (129 loc) 4.28 kB
// @remove-on-eject-begin /** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ // @remove-on-eject-end 'use strict'; // Do this as the first thing so that any code reading it knows the right env. process.env.BABEL_ENV = 'production'; process.env.NODE_ENV = 'production'; // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will // terminate the Node.js process with a non-zero exit code. process.on('unhandledRejection', err => { throw err; }); // Ensure environment variables are read. require('../config/env'); // @remove-on-eject-begin // Do the preflight checks (only happens before eject). const verifyPackageTree = require('./utils/verifyPackageTree'); if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') { verifyPackageTree(); } const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup'); verifyTypeScriptSetup(); // @remove-on-eject-end const chalk = require('react-dev-utils/chalk'); const fs = require('fs-extra'); const webpack = require('webpack'); const configFactory = require('../config/webpack.config'); const paths = require('../config/paths'); const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); const printBuildError = require('react-dev-utils/printBuildError'); // Warn and crash if required files are missing if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { process.exit(1); } // Generate configuration const conf = configFactory('production', 'node'); // Start the webpack build build(conf) .then( warnings => { if (warnings.length) { console.log(chalk.yellow('Compiled with warnings.\n')); console.log(warnings.join('\n\n')); console.log( '\nSearch for the ' + chalk.underline(chalk.yellow('keywords')) + ' to learn more about each warning.' ); console.log( 'To ignore, add ' + chalk.cyan('// eslint-disable-next-line') + ' to the line before.\n' ); } else { console.log(chalk.green('Compiled successfully.\n')); } }, err => { console.log(chalk.red('Failed to compile.\n')); printBuildError(err); process.exit(1); } ) .catch(err => { if (err && err.message) { console.log(err.message); } process.exit(1); }); // Create the production build and print the deployment instructions. function build(config) { console.log('Creating an optimized server production build...'); const compiler = webpack(config); return new Promise((resolve, reject) => { compiler.run((err, stats) => { let messages; if (err) { if (!err.message) { return reject(err); } let errMessage = err.message; messages = formatWebpackMessages({ errors: [errMessage], warnings: [], }); } else { messages = formatWebpackMessages( stats.toJson({ all: false, warnings: true, errors: true }) ); } if (messages.errors.length) { // Only keep the first error. Others are often indicative // of the same problem, but confuse the reader with noise. if (messages.errors.length > 1) { messages.errors.length = 1; } return reject(new Error(messages.errors.join('\n\n'))); } if ( process.env.CI && (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length ) { console.log( chalk.yellow( '\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n' ) ); return reject(new Error(messages.warnings.join('\n\n'))); } return resolve(messages.warnings); }); }); } function copyPublicFolder() { fs.copySync(paths.appPublic, paths.appBuild, { dereference: true, filter: file => file !== paths.appHtml, }); }