UNPKG

3.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
5const path = (0, tslib_1.__importStar)(require("path"));
6const typescript = (0, tslib_1.__importStar)(require("typescript"));
7const webpack_1 = (0, tslib_1.__importDefault)(require("webpack"));
8const formatWebpackMessages_1 = require("../lib/formatWebpackMessages");
9const paths_1 = require("../lib/paths");
10const env_1 = require("../util/env");
11const fileSizeReporter_1 = require("./util/fileSizeReporter");
12const getWebpackConfig_1 = require("./util/getWebpackConfig");
13const prodBundlePath = path.join(paths_1.paths.appBuild, paths_1.paths.prodBundle);
14const sizeBeforeBuild = (0, fileSizeReporter_1.getBundleSize)(prodBundlePath);
15const build = () => {
16 console.log(chalk_1.default.cyan('Creating an optimized production build...'));
17 console.log(chalk_1.default.green('Using TypeScript v' + typescript.version));
18 console.log();
19 const compiler = (0, webpack_1.default)((0, getWebpackConfig_1.getWebpackConfig)('production'));
20 return new Promise((resolve, reject) => {
21 compiler.run((err, stats) => {
22 if (err) {
23 return reject(err);
24 }
25 const messages = (0, formatWebpackMessages_1.formatWebpackMessages)(stats.toJson());
26 if (messages.errors.length) {
27 if (messages.errors.length > 1 && !env_1.RuntimeOptions.noCollapse) {
28 messages.errors.length = 1;
29 }
30 return reject(new Error(messages.errors.join('\n\n')));
31 }
32 if (env_1.IS_CI && messages.warnings.length) {
33 if (env_1.RuntimeOptions.bypassCiWarnings) {
34 console.log(chalk_1.default.yellow('\nBypassing warnings as CI errors due to --bypass-ci-warnings option.\n'));
35 }
36 else {
37 console.log(chalk_1.default.yellow('\nTreating warnings as errors because process.env.CI = true.\n' +
38 'Most CI servers set it automatically.\n'));
39 return reject(new Error(messages.warnings.join('\n\n')));
40 }
41 }
42 return resolve({
43 stats: stats,
44 warnings: messages.warnings,
45 });
46 });
47 });
48};
49build()
50 .then(({ warnings }) => {
51 if (warnings.length) {
52 console.log(chalk_1.default.yellow('Compiled with warnings.\n'));
53 console.log(warnings.join('\n\n'));
54 console.log('\nSearch for the ' +
55 chalk_1.default.cyan('keywords') +
56 ' to learn more about each warning.');
57 console.log('To ignore, add ' +
58 chalk_1.default.yellow('// eslint-disable-next-line') +
59 ' to the line before.\n');
60 }
61}, (err) => {
62 console.log(chalk_1.default.red('Failed to compile.\n'));
63 console.log(err.message);
64 console.log();
65 process.exit(1);
66})
67 .then(() => {
68 const sizeAfterBuild = (0, fileSizeReporter_1.getBundleSize)(prodBundlePath);
69 console.log();
70 console.log(chalk_1.default.greenBright('Successfully built bundle.prod.js!'));
71 console.log('Bundle size: ' + (0, fileSizeReporter_1.diffFileSize)(sizeBeforeBuild, sizeAfterBuild));
72 console.log();
73})
74 .catch((err) => {
75 if (err && err.message) {
76 console.log(err.message);
77 }
78 process.exit(1);
79});
80//# sourceMappingURL=build.js.map
\No newline at end of file