@henderea/static-site-builder 1.9.6 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/static-site-builder.js +37 -31
- package/config/cache-config.js +99 -99
- package/config/env.js +15 -14
- package/config/paths.js +58 -54
- package/config/webpack.config.dev.js +172 -169
- package/config/webpack.config.prod.js +259 -255
- package/package.json +43 -30
- package/scripts/build.js +90 -90
- package/scripts/watch.js +83 -83
- package/utils/FileSizeReporter.js +27 -27
- package/utils/checkRequiredFiles.js +5 -7
- package/utils/formatWebpackMessages.js +13 -15
- package/utils/printBuildError.js +5 -5
- package/utils/workspaceUtils.js +16 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henderea/static-site-builder",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "A static site builder",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "henderea/static-site-builder.git",
|
|
@@ -19,43 +19,56 @@
|
|
|
19
19
|
"bin": {
|
|
20
20
|
"static-site-builder": "bin/static-site-builder.js"
|
|
21
21
|
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"lint": "eslint bin config scripts utils",
|
|
24
|
+
"lint:fix": "eslint --fix bin config scripts utils"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
22
27
|
"dependencies": {
|
|
23
|
-
"@babel/core": "^7.
|
|
28
|
+
"@babel/core": "^7.16.5",
|
|
24
29
|
"babel-core": "^6.26.3",
|
|
25
|
-
"babel-loader": "^8.2.
|
|
26
|
-
"case-sensitive-paths-webpack-plugin": "^2.
|
|
27
|
-
"chalk": "^
|
|
28
|
-
"copy-webpack-plugin": "^
|
|
30
|
+
"babel-loader": "^8.2.3",
|
|
31
|
+
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
32
|
+
"chalk": "^5.0.0",
|
|
33
|
+
"copy-webpack-plugin": "^10.2.0",
|
|
29
34
|
"cross-spawn": "^7.0.3",
|
|
30
|
-
"css-loader": "^5.
|
|
31
|
-
"dotenv": "^
|
|
35
|
+
"css-loader": "^6.5.1",
|
|
36
|
+
"dotenv": "^10.0.0",
|
|
32
37
|
"dotenv-expand": "^5.1.0",
|
|
33
|
-
"ejs": "^3.1.
|
|
34
|
-
"eslint": "^
|
|
38
|
+
"ejs": "^3.1.6",
|
|
39
|
+
"eslint": "^8.5.0",
|
|
35
40
|
"file-loader": "^6.2.0",
|
|
36
|
-
"filesize": "^
|
|
41
|
+
"filesize": "^8.0.6",
|
|
37
42
|
"find-pkg": "^2.0.0",
|
|
38
|
-
"globby": "^
|
|
39
|
-
"gzip-size": "^
|
|
40
|
-
"handlebars": "^4.7.
|
|
41
|
-
"html-webpack-plugin": "^5.
|
|
42
|
-
"lodash": "^4.17.
|
|
43
|
-
"mini-css-extract-plugin": "^
|
|
43
|
+
"globby": "^12.0.2",
|
|
44
|
+
"gzip-size": "^7.0.0",
|
|
45
|
+
"handlebars": "^4.7.7",
|
|
46
|
+
"html-webpack-plugin": "^5.5.0",
|
|
47
|
+
"lodash": "^4.17.21",
|
|
48
|
+
"mini-css-extract-plugin": "^2.4.5",
|
|
44
49
|
"moment": "^2.29.1",
|
|
45
50
|
"moment-locales-webpack-plugin": "^1.2.0",
|
|
46
|
-
"node-sass": "^
|
|
47
|
-
"postcss-loader": "^
|
|
48
|
-
"postcss-preset-env": "^
|
|
51
|
+
"node-sass": "^7.0.0",
|
|
52
|
+
"postcss-loader": "^6.2.1",
|
|
53
|
+
"postcss-preset-env": "^7.0.2",
|
|
49
54
|
"recursive-readdir": "^2.2.2",
|
|
50
|
-
"sass-loader": "^
|
|
51
|
-
"strip-ansi": "^
|
|
52
|
-
"style-loader": "^
|
|
53
|
-
"thread-loader": "^3.0.
|
|
54
|
-
"ts-loader": "^
|
|
55
|
-
"tsconfig-paths-webpack-plugin": "^3.
|
|
56
|
-
"typescript": "^4.
|
|
57
|
-
"webpack": "^5.
|
|
58
|
-
"webpack-manifest-plugin": "^
|
|
59
|
-
"workbox-webpack-plugin": "^6.
|
|
55
|
+
"sass-loader": "^12.4.0",
|
|
56
|
+
"strip-ansi": "^7.0.1",
|
|
57
|
+
"style-loader": "^3.3.1",
|
|
58
|
+
"thread-loader": "^3.0.4",
|
|
59
|
+
"ts-loader": "^9.2.6",
|
|
60
|
+
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
61
|
+
"typescript": "^4.5.4",
|
|
62
|
+
"webpack": "^5.65.0",
|
|
63
|
+
"webpack-manifest-plugin": "^4.0.2",
|
|
64
|
+
"workbox-webpack-plugin": "^6.4.2"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@babel/eslint-parser": "^7.16.5",
|
|
68
|
+
"eslint-config-henderea": "1.0.9",
|
|
69
|
+
"eslint-plugin-import": "^2.25.3"
|
|
70
|
+
},
|
|
71
|
+
"eslintConfig": {
|
|
72
|
+
"extends": "henderea"
|
|
60
73
|
}
|
|
61
74
|
}
|
package/scripts/build.js
CHANGED
|
@@ -7,22 +7,22 @@ process.env.NODE_ENV = 'production';
|
|
|
7
7
|
// Makes the script crash on unhandled rejections instead of silently
|
|
8
8
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
9
9
|
// terminate the Node.js process with a non-zero exit code.
|
|
10
|
-
process.on('unhandledRejection', err => {
|
|
11
|
-
|
|
10
|
+
process.on('unhandledRejection', (err) => {
|
|
11
|
+
throw err;
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
import '../config/env.js';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
// import path from 'path';
|
|
17
|
+
import chalk from 'chalk';
|
|
18
|
+
import fs from 'fs-extra';
|
|
19
|
+
import webpack from 'webpack';
|
|
20
|
+
import config from '../config/webpack.config.prod.js';
|
|
21
|
+
import * as paths from '../config/paths.js';
|
|
22
|
+
import checkRequiredFiles from '../utils/checkRequiredFiles.js';
|
|
23
|
+
import formatWebpackMessages from '../utils/formatWebpackMessages.js';
|
|
24
|
+
import * as FileSizeReporter from '../utils/FileSizeReporter.js';
|
|
25
|
+
import printBuildError from '../utils/printBuildError.js';
|
|
26
26
|
|
|
27
27
|
const measureFileSizesBeforeBuild =
|
|
28
28
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
@@ -32,97 +32,97 @@ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
|
32
32
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
33
33
|
|
|
34
34
|
if(!checkRequiredFiles([paths.appTemplate, paths.appIndex])) {
|
|
35
|
-
|
|
35
|
+
process.exit(1);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
measureFileSizesBeforeBuild(paths.appDist)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
.then((previousFileSizes) => {
|
|
40
|
+
// Remove all content but keep the directory so that
|
|
41
|
+
// if you're in it, you don't end up in Trash
|
|
42
|
+
fs.emptyDirSync(paths.appDist);
|
|
43
|
+
// Start the webpack build
|
|
44
|
+
return build(previousFileSizes);
|
|
45
|
+
})
|
|
46
|
+
.then(
|
|
47
|
+
({ stats, previousFileSizes, warnings }) => {
|
|
48
|
+
if(warnings.length) {
|
|
49
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
50
|
+
console.log(warnings.join('\n\n'));
|
|
51
|
+
console.log(
|
|
52
|
+
'\nSearch for the ' +
|
|
53
53
|
chalk.underline(chalk.yellow('keywords')) +
|
|
54
54
|
' to learn more about each warning.'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
);
|
|
56
|
+
console.log(
|
|
57
|
+
'To ignore, add ' +
|
|
58
58
|
chalk.cyan('// eslint-disable-next-line') +
|
|
59
59
|
' to the line before.\n'
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
);
|
|
61
|
+
} else {
|
|
62
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
console.log('File sizes after gzip:\n');
|
|
66
|
+
printFileSizesAfterBuild(
|
|
67
|
+
stats,
|
|
68
|
+
previousFileSizes,
|
|
69
|
+
paths.appDist,
|
|
70
|
+
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
71
|
+
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
72
|
+
);
|
|
73
|
+
console.log();
|
|
74
|
+
},
|
|
75
|
+
(err) => {
|
|
76
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
77
|
+
printBuildError(err);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
.catch((err) => {
|
|
82
|
+
if(err && err.message) {
|
|
83
|
+
console.log(err.message);
|
|
84
|
+
}
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
|
87
87
|
|
|
88
88
|
// Create the production build and print the deployment instructions.
|
|
89
89
|
function build(previousFileSizes) {
|
|
90
|
-
|
|
90
|
+
console.log('Creating an optimized production build...');
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
92
|
+
let compiler = webpack(config);
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
compiler.run((err, stats) => {
|
|
95
|
+
if(err) {
|
|
96
|
+
return reject(err);
|
|
97
|
+
}
|
|
98
|
+
const messages = formatWebpackMessages(stats.toJson({}, true));
|
|
99
|
+
if(messages.errors.length) {
|
|
100
|
+
// Only keep the first error. Others are often indicative
|
|
101
|
+
// of the same problem, but confuse the reader with noise.
|
|
102
|
+
if(messages.errors.length > 1) {
|
|
103
|
+
messages.errors.length = 1;
|
|
104
|
+
}
|
|
105
|
+
return reject(new Error(messages.errors.join('\n\n')));
|
|
106
|
+
}
|
|
107
|
+
if(
|
|
108
|
+
process.env.CI &&
|
|
109
109
|
(typeof process.env.CI !== 'string' ||
|
|
110
110
|
process.env.CI.toLowerCase() !== 'false') &&
|
|
111
111
|
messages.warnings.length
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
) {
|
|
113
|
+
console.log(
|
|
114
|
+
chalk.yellow(
|
|
115
|
+
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
116
116
|
'Most CI servers set it automatically.\n'
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
return reject(new Error(messages.warnings.join('\n\n')));
|
|
120
|
+
}
|
|
121
|
+
return resolve({
|
|
122
|
+
stats,
|
|
123
|
+
previousFileSizes,
|
|
124
|
+
warnings: messages.warnings,
|
|
125
|
+
});
|
|
127
126
|
});
|
|
128
|
-
}
|
|
127
|
+
});
|
|
128
|
+
}
|
package/scripts/watch.js
CHANGED
|
@@ -7,22 +7,22 @@ process.env.NODE_ENV = 'development';
|
|
|
7
7
|
// Makes the script crash on unhandled rejections instead of silently
|
|
8
8
|
// ignoring them. In the future, promise rejections that are not handled will
|
|
9
9
|
// terminate the Node.js process with a non-zero exit code.
|
|
10
|
-
process.on('unhandledRejection', err => {
|
|
11
|
-
|
|
10
|
+
process.on('unhandledRejection', (err) => {
|
|
11
|
+
throw err;
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
import '../config/env.js';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
// import path from 'path';
|
|
17
|
+
import chalk from 'chalk';
|
|
18
|
+
import fs from 'fs-extra';
|
|
19
|
+
import webpack from 'webpack';
|
|
20
|
+
import config from '../config/webpack.config.dev.js';
|
|
21
|
+
import * as paths from '../config/paths.js';
|
|
22
|
+
import checkRequiredFiles from '../utils/checkRequiredFiles.js';
|
|
23
|
+
import formatWebpackMessages from '../utils/formatWebpackMessages.js';
|
|
24
|
+
import * as FileSizeReporter from '../utils/FileSizeReporter.js';
|
|
25
|
+
import printBuildError from '../utils/printBuildError.js';
|
|
26
26
|
|
|
27
27
|
const measureFileSizesBeforeBuild =
|
|
28
28
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
@@ -32,89 +32,89 @@ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
|
32
32
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
33
33
|
|
|
34
34
|
if(!checkRequiredFiles([paths.appTemplate, paths.appIndex])) {
|
|
35
|
-
|
|
35
|
+
process.exit(1);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
measureFileSizesBeforeBuild(paths.appBuild)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
.then((previousFileSizes) => {
|
|
40
|
+
// Remove all content but keep the directory so that
|
|
41
|
+
// if you're in it, you don't end up in Trash
|
|
42
|
+
fs.emptyDirSync(paths.appBuild);
|
|
43
|
+
// Start the webpack build
|
|
44
|
+
return build(previousFileSizes,
|
|
45
|
+
({ stats, previousFileSizes, warnings }) => {
|
|
46
|
+
if(warnings.length) {
|
|
47
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
48
|
+
console.log(warnings.join('\n\n'));
|
|
49
|
+
console.log(
|
|
50
|
+
'\nSearch for the ' +
|
|
51
51
|
chalk.underline(chalk.yellow('keywords')) +
|
|
52
52
|
' to learn more about each warning.'
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
);
|
|
54
|
+
console.log(
|
|
55
|
+
'To ignore, add ' +
|
|
56
56
|
chalk.cyan('// eslint-disable-next-line') +
|
|
57
57
|
' to the line before.\n'
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
console.log('File sizes after gzip:\n');
|
|
64
|
-
printFileSizesAfterBuild(
|
|
65
|
-
stats,
|
|
66
|
-
previousFileSizes,
|
|
67
|
-
paths.appBuild,
|
|
68
|
-
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
69
|
-
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
70
|
-
);
|
|
71
|
-
console.log();
|
|
72
|
-
},
|
|
73
|
-
err => {
|
|
74
|
-
console.log(chalk.red('Failed to compile.\n'));
|
|
75
|
-
printBuildError(err);
|
|
76
|
-
});
|
|
77
|
-
})
|
|
78
|
-
.catch(err => {
|
|
79
|
-
if(err && err.message) {
|
|
80
|
-
console.log(err.message);
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
81
61
|
}
|
|
82
|
-
|
|
62
|
+
|
|
63
|
+
console.log('File sizes after gzip:\n');
|
|
64
|
+
printFileSizesAfterBuild(
|
|
65
|
+
stats,
|
|
66
|
+
previousFileSizes,
|
|
67
|
+
paths.appBuild,
|
|
68
|
+
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
69
|
+
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
70
|
+
);
|
|
71
|
+
console.log();
|
|
72
|
+
},
|
|
73
|
+
(err) => {
|
|
74
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
75
|
+
printBuildError(err);
|
|
76
|
+
});
|
|
77
|
+
})
|
|
78
|
+
.catch((err) => {
|
|
79
|
+
if(err && err.message) {
|
|
80
|
+
console.log(err.message);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
83
|
|
|
84
84
|
// Create the production build and print the deployment instructions.
|
|
85
85
|
function build(previousFileSizes, resolve, reject) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
86
|
+
let compiler = webpack(config);
|
|
87
|
+
compiler.watch({}, (err, stats) => {
|
|
88
|
+
if(err) {
|
|
89
|
+
return reject(err);
|
|
90
|
+
}
|
|
91
|
+
const messages = formatWebpackMessages(stats.toJson({}, true));
|
|
92
|
+
if(messages.errors.length) {
|
|
93
|
+
// Only keep the first error. Others are often indicative
|
|
94
|
+
// of the same problem, but confuse the reader with noise.
|
|
95
|
+
if(messages.errors.length > 1) {
|
|
96
|
+
messages.errors.length = 1;
|
|
97
|
+
}
|
|
98
|
+
return reject(new Error(messages.errors.join('\n\n')));
|
|
99
|
+
}
|
|
100
|
+
if(
|
|
101
|
+
process.env.CI &&
|
|
102
102
|
(typeof process.env.CI !== 'string' ||
|
|
103
103
|
process.env.CI.toLowerCase() !== 'false') &&
|
|
104
104
|
messages.warnings.length
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
) {
|
|
106
|
+
console.log(
|
|
107
|
+
chalk.yellow(
|
|
108
|
+
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
109
109
|
'Most CI servers set it automatically.\n'
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
return reject(new Error(messages.warnings.join('\n\n')));
|
|
113
|
+
}
|
|
114
|
+
return resolve({
|
|
115
|
+
stats,
|
|
116
|
+
previousFileSizes,
|
|
117
|
+
warnings: messages.warnings,
|
|
119
118
|
});
|
|
120
|
-
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
import filesize from 'filesize';
|
|
14
|
+
import recursive from 'recursive-readdir';
|
|
15
|
+
import stripAnsi from 'strip-ansi';
|
|
16
|
+
import { gzipSizeSync } from 'gzip-size';
|
|
17
17
|
|
|
18
18
|
// Prints a detailed summary of build files.
|
|
19
19
|
function printFileSizesAfterBuild(
|
|
@@ -26,13 +26,13 @@ function printFileSizesAfterBuild(
|
|
|
26
26
|
var root = previousSizeMap.root;
|
|
27
27
|
var sizes = previousSizeMap.sizes;
|
|
28
28
|
var assets = (webpackStats.stats || [webpackStats])
|
|
29
|
-
.map(stats =>
|
|
29
|
+
.map((stats) =>
|
|
30
30
|
stats
|
|
31
31
|
.toJson()
|
|
32
|
-
.assets.filter(asset => /\.(js|css)$/.test(asset.name))
|
|
33
|
-
.map(asset => {
|
|
32
|
+
.assets.filter((asset) => /\.(js|css)$/.test(asset.name))
|
|
33
|
+
.map((asset) => {
|
|
34
34
|
var fileContents = fs.readFileSync(path.join(root, asset.name));
|
|
35
|
-
var size =
|
|
35
|
+
var size = gzipSizeSync(fileContents);
|
|
36
36
|
var previousSize = sizes[removeFileNameHash(root, asset.name)];
|
|
37
37
|
var difference = getDifferenceLabel(size, previousSize);
|
|
38
38
|
return {
|
|
@@ -51,13 +51,13 @@ function printFileSizesAfterBuild(
|
|
|
51
51
|
assets.sort((a, b) => b.size - a.size);
|
|
52
52
|
var longestSizeLabelLength = Math.max.apply(
|
|
53
53
|
null,
|
|
54
|
-
assets.map(a => stripAnsi(a.sizeLabel).length)
|
|
54
|
+
assets.map((a) => stripAnsi(a.sizeLabel).length)
|
|
55
55
|
);
|
|
56
56
|
var suggestBundleSplitting = false;
|
|
57
|
-
assets.forEach(asset => {
|
|
57
|
+
assets.forEach((asset) => {
|
|
58
58
|
var sizeLabel = asset.sizeLabel;
|
|
59
59
|
var sizeLength = stripAnsi(sizeLabel).length;
|
|
60
|
-
if
|
|
60
|
+
if(sizeLength < longestSizeLabelLength) {
|
|
61
61
|
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
|
|
62
62
|
sizeLabel += rightPadding;
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ function printFileSizesAfterBuild(
|
|
|
66
66
|
? maxBundleGzipSize
|
|
67
67
|
: maxChunkGzipSize;
|
|
68
68
|
var isLarge = maxRecommendedSize && asset.size > maxRecommendedSize;
|
|
69
|
-
if
|
|
69
|
+
if(isLarge && path.extname(asset.name) === '.js') {
|
|
70
70
|
suggestBundleSplitting = true;
|
|
71
71
|
}
|
|
72
72
|
console.log(
|
|
@@ -77,7 +77,7 @@ function printFileSizesAfterBuild(
|
|
|
77
77
|
chalk.cyan(asset.name)
|
|
78
78
|
);
|
|
79
79
|
});
|
|
80
|
-
if
|
|
80
|
+
if(suggestBundleSplitting) {
|
|
81
81
|
console.log();
|
|
82
82
|
console.log(
|
|
83
83
|
chalk.yellow('The bundle size is significantly larger than recommended.')
|
|
@@ -111,11 +111,11 @@ function getDifferenceLabel(currentSize, previousSize) {
|
|
|
111
111
|
var FIFTY_KILOBYTES = 1024 * 50;
|
|
112
112
|
var difference = currentSize - previousSize;
|
|
113
113
|
var fileSize = !Number.isNaN(difference) ? filesize(difference) : 0;
|
|
114
|
-
if
|
|
114
|
+
if(difference >= FIFTY_KILOBYTES) {
|
|
115
115
|
return chalk.red('+' + fileSize);
|
|
116
|
-
} else if
|
|
116
|
+
} else if(difference < FIFTY_KILOBYTES && difference > 0) {
|
|
117
117
|
return chalk.yellow('+' + fileSize);
|
|
118
|
-
} else if
|
|
118
|
+
} else if(difference < 0) {
|
|
119
119
|
return chalk.green(fileSize);
|
|
120
120
|
} else {
|
|
121
121
|
return '';
|
|
@@ -123,16 +123,16 @@ function getDifferenceLabel(currentSize, previousSize) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
function measureFileSizesBeforeBuild(buildFolder) {
|
|
126
|
-
return new Promise(resolve => {
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
127
|
recursive(buildFolder, (err, fileNames) => {
|
|
128
128
|
var sizes;
|
|
129
|
-
if
|
|
129
|
+
if(!err && fileNames) {
|
|
130
130
|
sizes = fileNames
|
|
131
|
-
.filter(fileName => /\.(js|css)$/.test(fileName))
|
|
131
|
+
.filter((fileName) => /\.(js|css)$/.test(fileName))
|
|
132
132
|
.reduce((memo, fileName) => {
|
|
133
133
|
var contents = fs.readFileSync(fileName);
|
|
134
134
|
var key = removeFileNameHash(buildFolder, fileName);
|
|
135
|
-
memo[key] =
|
|
135
|
+
memo[key] = gzipSizeSync(contents);
|
|
136
136
|
return memo;
|
|
137
137
|
}, {});
|
|
138
138
|
}
|
|
@@ -144,7 +144,7 @@ function measureFileSizesBeforeBuild(buildFolder) {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
measureFileSizesBeforeBuild
|
|
149
|
-
printFileSizesAfterBuild
|
|
150
|
-
};
|
|
147
|
+
export {
|
|
148
|
+
measureFileSizesBeforeBuild,
|
|
149
|
+
printFileSizesAfterBuild
|
|
150
|
+
};
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import chalk from 'chalk';
|
|
13
13
|
|
|
14
|
-
function checkRequiredFiles(files) {
|
|
14
|
+
export default function checkRequiredFiles(files) {
|
|
15
15
|
var currentFilePath;
|
|
16
16
|
try {
|
|
17
|
-
files.forEach(filePath => {
|
|
17
|
+
files.forEach((filePath) => {
|
|
18
18
|
currentFilePath = filePath;
|
|
19
19
|
fs.accessSync(filePath, fs.F_OK);
|
|
20
20
|
});
|
|
@@ -28,5 +28,3 @@ function checkRequiredFiles(files) {
|
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
module.exports = checkRequiredFiles;
|