|
1 | | -var fs = require('fs-extra'); |
2 | | -var path = require('path'); |
3 | | -var webpack = require('webpack'); |
4 | | -var paths = require('../config/paths'); |
5 | | -var config = require('../config/webpack.config.vendor'); |
6 | | -var clearConsole = require('react-dev-utils/clearConsole'); |
7 | | -var os = require('os'); |
8 | | -var chalk = require('chalk'); |
9 | | -var printErrors = require('../utils/printErrors'); |
| 1 | +var fs = require("fs-extra"); |
| 2 | +var path = require("path"); |
| 3 | +var webpack = require("webpack"); |
| 4 | +var paths = require("../config/paths"); |
| 5 | +var config = require("../config/webpack.config.vendor"); |
| 6 | +var clearConsole = require("react-dev-utils/clearConsole"); |
| 7 | +var os = require("os"); |
| 8 | +var chalk = require("chalk"); |
| 9 | +var printErrors = require("../utils/printErrors"); |
10 | 10 | var environment = process.env.NODE_ENV; |
11 | | -var hashFilePrefix = 'REACT_APP_PACKAGE_JSON_MD5_'; |
12 | | -var vendorManifestId = require('../utils/vendorManifestId'); |
| 11 | +var vendorHash = require("../utils/vendorHash"); |
13 | 12 |
|
14 | 13 | module.exports = (callback, args) => { |
15 | 14 | if (shouldManifestUpdate()) { |
16 | | - fs.emptyDirSync(paths.vendorPath); |
17 | | - var compiler = webpack(config); |
18 | | - console.log('Bundling vendor files for faster rebuilds...'); |
19 | | - return compiler.run((err, stats) => { |
20 | | - if (err) { |
21 | | - printErrors('Failed to compile.', [err]); |
22 | | - process.exit(1); |
| 15 | + // fs.emptyDirSync(paths.vendorPath); |
| 16 | + return fs.readdir(paths.vendorPath, (err, files) => { |
| 17 | + try { |
| 18 | + files.filter(file => !file.indexOf(environment)).forEach(file => { |
| 19 | + fs.unlinkSync(path.join(paths.vendorPath, file)); |
| 20 | + }); |
| 21 | + } catch (e) { |
23 | 22 | } |
| 23 | + var compiler = webpack(config); |
| 24 | + console.log("Bundling vendor files for faster rebuilds..."); |
| 25 | + compiler.run((err, stats) => { |
| 26 | + if (err) { |
| 27 | + printErrors("Failed to compile.", [err]); |
| 28 | + process.exit(1); |
| 29 | + } |
24 | 30 |
|
25 | | - if (stats.compilation.errors.length) { |
26 | | - printErrors('Failed to compile.', stats.compilation.errors); |
27 | | - process.exit(1); |
28 | | - } |
| 31 | + if (stats.compilation.errors.length) { |
| 32 | + printErrors("Failed to compile.", stats.compilation.errors); |
| 33 | + process.exit(1); |
| 34 | + } |
29 | 35 |
|
30 | | - if (process.env.CI && stats.compilation.warnings.length) { |
31 | | - printErrors( |
32 | | - 'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.', |
33 | | - stats.compilation.warnings |
34 | | - ); |
35 | | - process.exit(1); |
36 | | - } |
| 36 | + if (process.env.CI && stats.compilation.warnings.length) { |
| 37 | + printErrors( |
| 38 | + "Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.", |
| 39 | + stats.compilation.warnings |
| 40 | + ); |
| 41 | + process.exit(1); |
| 42 | + } |
37 | 43 |
|
38 | | - console.log(chalk.green('Vendor compiled successfully.')); |
39 | | - console.log(); |
40 | | - fs.writeFileSync( |
41 | | - path.join(os.tmpdir(), hashFilePrefix + vendorManifestId) |
42 | | - ); |
43 | | - callback(); |
| 44 | + console.log(chalk.green("Vendor compiled successfully.")); |
| 45 | + console.log(); |
| 46 | + callback(); |
| 47 | + }); |
44 | 48 | }); |
45 | 49 | } |
46 | | - console.log('Vendor file is up to date! No need to rebuild it'); |
| 50 | + console.log("Vendor file is up to date! No need to rebuild it"); |
47 | 51 | return callback(); |
48 | 52 | }; |
49 | 53 |
|
50 | 54 | function manifestExists() { |
51 | | - return fs.existsSync( |
52 | | - path.join(paths.vendorPath, 'manifest.' + vendorManifestId + '.json') |
53 | | - ); |
| 55 | + return fs.existsSync(path.join(paths.vendorPath, vendorHash + ".json")); |
54 | 56 | } |
55 | 57 |
|
56 | 58 | function manifestStale() { |
57 | | - if (md5Exists(vendorManifestId)) { |
| 59 | + if (vendorHash) { |
58 | 60 | return false; |
59 | 61 | } |
60 | 62 | return true; |
61 | 63 | } |
62 | 64 |
|
63 | | -function md5Exists(md5) { |
64 | | - return fs.existsSync(path.join(os.tmpdir(), hashFilePrefix + md5)); |
65 | | -} |
66 | | - |
67 | 65 | function shouldManifestUpdate() { |
| 66 | + var isExists = manifestExists(); |
68 | 67 | clearConsole(); |
69 | | - console.log('Using ' + vendorManifestId + ' vendor build'); |
70 | | - if (!manifestExists()) { |
71 | | - console.log('Vendor file needs to be created...'); |
| 68 | + console.log("Using " + vendorHash + " vendor build"); |
| 69 | + if (!isExists) { |
| 70 | + console.log("Vendor file needs to be created..."); |
72 | 71 | return true; |
73 | 72 | } |
74 | | - if (manifestExists() && manifestStale()) { |
75 | | - console.log('Vendor file needs to be updated...'); |
| 73 | + if (isExists && manifestStale()) { |
| 74 | + console.log("Vendor file needs to be updated..."); |
76 | 75 | return true; |
77 | 76 | } |
78 | 77 | return false; |
|
0 commit comments