|
1 | 1 | /** |
2 | 2 | * BSD License |
3 | 3 | * For create-react-app software |
4 | | - * |
| 4 | + * |
5 | 5 | * Copyright (c) 2016-present, Facebook, Inc. All rights reserved. |
6 | 6 | * Redistribution and use in source and binary forms, with or without modification, |
7 | 7 | * are permitted provided that the following conditions are met: |
8 | | - * |
| 8 | + * |
9 | 9 | * Redistributions of source code must retain the above copyright notice, this |
10 | 10 | * list of conditions and the following disclaimer. |
11 | | - * |
| 11 | + * |
12 | 12 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | 13 | * this list of conditions and the following disclaimer in the documentation |
14 | 14 | * and/or other materials provided with the distribution. |
15 | | - * |
| 15 | + * |
16 | 16 | * Neither the name Facebook nor the names of its contributors may be used to |
17 | 17 | * endorse or promote products derived from this software without specific |
18 | 18 | * prior written permission. |
19 | | - * |
20 | | - * |
| 19 | + * |
| 20 | + * |
21 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
22 | 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
23 | 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | 32 |
|
33 | | -'use strict'; |
| 33 | +'use strict' |
34 | 34 |
|
35 | | -process.env.NODE_ENV = 'production'; |
| 35 | +process.env.NODE_ENV = 'production' |
36 | 36 |
|
37 | 37 | const fs = require('fs-extra') |
38 | 38 | const chalk = require('chalk') |
39 | 39 | const webpack = require('webpack') |
40 | | -const config = require('./configs/webpack.config.prod') |
| 40 | +const config = require('../configs/webpack.config.prod') |
41 | 41 | const path = require('path') |
42 | 42 |
|
43 | 43 | const buildPath = path.join(process.cwd(), 'build') |
44 | 44 | const publicPath = path.join(process.cwd(), 'public') |
45 | 45 |
|
46 | | - |
47 | 46 | // Remove all content but keep the directory so that |
48 | 47 | // if you're in it, you don't end up in Trash |
49 | | -fs.emptyDirSync(buildPath); |
| 48 | +fs.emptyDirSync(buildPath) |
50 | 49 |
|
51 | 50 | // Start the webpack build |
52 | | -build(); |
| 51 | +build() |
53 | 52 |
|
54 | 53 | // Merge with the public folder |
55 | | -copyPublicFolder(); |
56 | | - |
| 54 | +copyPublicFolder() |
57 | 55 |
|
58 | 56 | // Print out errors |
59 | | -function printErrors(summary, errors) { |
60 | | - console.log(chalk.red(summary)); |
61 | | - console.log(); |
| 57 | +function printErrors (summary, errors) { |
| 58 | + console.log(chalk.red(summary)) |
| 59 | + console.log() |
62 | 60 | errors.forEach(err => { |
63 | | - console.log(err.message || err); |
64 | | - console.log(); |
65 | | - }); |
| 61 | + console.log(err.message || err) |
| 62 | + console.log() |
| 63 | + }) |
66 | 64 | } |
67 | 65 |
|
68 | | - |
69 | 66 | // Merge with the public folder |
70 | | -function copyPublicFolder() { |
| 67 | +function copyPublicFolder () { |
71 | 68 | fs.copySync(publicPath, buildPath, { |
72 | | - dereference: true, |
| 69 | + dereference: true |
73 | 70 | // filter: file => file !== resolveApp('public/index.html'), |
74 | | - }); |
| 71 | + }) |
75 | 72 | } |
76 | 73 |
|
77 | | - |
78 | | - |
79 | 74 | // Create the production build and print the deployment instructions. |
80 | | -function build() { |
81 | | - console.log('Creating an optimized production build...'); |
| 75 | +function build () { |
| 76 | + console.log('Creating an optimized production build...') |
82 | 77 |
|
83 | | - let compiler; |
| 78 | + let compiler |
84 | 79 | try { |
85 | | - compiler = webpack(config); |
| 80 | + compiler = webpack(config) |
86 | 81 | } catch (err) { |
87 | | - printErrors('Failed to compile.', [err]); |
88 | | - process.exit(1); |
| 82 | + printErrors('Failed to compile.', [err]) |
| 83 | + process.exit(1) |
89 | 84 | } |
90 | 85 |
|
91 | 86 | compiler.run((err, stats) => { |
92 | 87 | if (err) { |
93 | | - printErrors('Failed to compile.', [err]); |
94 | | - process.exit(1); |
| 88 | + printErrors('Failed to compile.', [err]) |
| 89 | + process.exit(1) |
95 | 90 | } |
96 | 91 |
|
97 | 92 | if (stats.compilation.errors.length) { |
98 | | - printErrors('Failed to compile.', stats.compilation.errors); |
99 | | - process.exit(1); |
| 93 | + printErrors('Failed to compile.', stats.compilation.errors) |
| 94 | + process.exit(1) |
100 | 95 | } |
101 | 96 |
|
102 | 97 | if (process.env.CI && stats.compilation.warnings.length) { |
103 | 98 | printErrors( |
104 | 99 | 'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.', |
105 | 100 | stats.compilation.warnings |
106 | | - ); |
107 | | - process.exit(1); |
| 101 | + ) |
| 102 | + process.exit(1) |
108 | 103 | } |
109 | 104 |
|
110 | | - console.log(chalk.green('Compiled successfully.')); |
111 | | - console.log(); |
112 | | - }); |
| 105 | + console.log(chalk.green('Compiled successfully.')) |
| 106 | + console.log() |
| 107 | + }) |
113 | 108 | } |
114 | 109 |
|
115 | | - |
116 | 110 | // const fs = require('fs-extra') |
117 | 111 | // const path = require('path') |
118 | 112 | // const mkdirp = require('mkdirp') |
|
0 commit comments