@modern-js/builder 2.26.0 → 2.27.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/CHANGELOG.md +19 -0
- package/dist/createBuilder.d.ts +1 -1
- package/dist/createBuilder.js +48 -38
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -8
- package/dist/plugins/antd.d.ts +1 -1
- package/dist/plugins/antd.js +52 -30
- package/dist/plugins/arco.d.ts +1 -1
- package/dist/plugins/arco.js +43 -35
- package/dist/plugins/asset.d.ts +1 -1
- package/dist/plugins/asset.js +29 -25
- package/dist/plugins/assetsRetry.d.ts +1 -1
- package/dist/plugins/assetsRetry.js +34 -51
- package/dist/plugins/bundleAnalyzer.d.ts +1 -1
- package/dist/plugins/bundleAnalyzer.js +29 -50
- package/dist/plugins/cache.d.ts +1 -1
- package/dist/plugins/cache.js +68 -87
- package/dist/plugins/checkSyntax.d.ts +1 -1
- package/dist/plugins/checkSyntax.js +40 -54
- package/dist/plugins/cleanOutput.d.ts +1 -1
- package/dist/plugins/cleanOutput.js +22 -38
- package/dist/plugins/devtool.d.ts +1 -1
- package/dist/plugins/devtool.js +23 -21
- package/dist/plugins/entry.d.ts +1 -1
- package/dist/plugins/entry.js +23 -19
- package/dist/plugins/externals.d.ts +1 -1
- package/dist/plugins/externals.js +28 -25
- package/dist/plugins/fileSize.d.ts +1 -1
- package/dist/plugins/fileSize.js +124 -130
- package/dist/plugins/html.d.ts +1 -1
- package/dist/plugins/html.js +203 -206
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +40 -53
- package/dist/plugins/inlineChunk.d.ts +1 -1
- package/dist/plugins/inlineChunk.js +50 -59
- package/dist/plugins/moment.d.ts +1 -1
- package/dist/plugins/moment.js +23 -20
- package/dist/plugins/rem.d.ts +1 -1
- package/dist/plugins/rem.js +74 -97
- package/dist/plugins/sourceBuild.d.ts +12 -12
- package/dist/plugins/sourceBuild.js +125 -109
- package/dist/plugins/splitChunks.d.ts +1 -1
- package/dist/plugins/splitChunks.js +206 -229
- package/dist/plugins/startUrl.d.ts +1 -1
- package/dist/plugins/startUrl.js +62 -78
- package/dist/plugins/svg.d.ts +1 -1
- package/dist/plugins/svg.js +64 -81
- package/dist/plugins/target.d.ts +1 -1
- package/dist/plugins/target.js +52 -31
- package/dist/plugins/toml.d.ts +1 -1
- package/dist/plugins/toml.js +16 -15
- package/dist/plugins/tsChecker.d.ts +1 -1
- package/dist/plugins/tsChecker.js +69 -92
- package/dist/plugins/wasm.d.ts +1 -1
- package/dist/plugins/wasm.js +31 -32
- package/dist/plugins/yaml.d.ts +1 -1
- package/dist/plugins/yaml.js +16 -15
- package/package.json +11 -9
package/dist/plugins/fileSize.js
CHANGED
|
@@ -1,143 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
17
4
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
filterAsset: function() {
|
|
14
|
+
return filterAsset;
|
|
15
|
+
},
|
|
16
|
+
builderPluginFileSize: function() {
|
|
17
|
+
return builderPluginFileSize;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
21
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
22
|
+
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
23
|
+
const _chalk = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/chalk"));
|
|
24
|
+
const _buildershared = require("@modern-js/builder-shared");
|
|
38
25
|
const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
39
|
-
exports.filterAsset = filterAsset;
|
|
40
26
|
const getAssetColor = (size) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
if (size > 300 * 1e3) {
|
|
28
|
+
return _chalk.default.bold.red;
|
|
29
|
+
}
|
|
30
|
+
if (size > 100 * 1e3) {
|
|
31
|
+
return _chalk.default.yellow;
|
|
32
|
+
}
|
|
33
|
+
return _chalk.default.green;
|
|
48
34
|
};
|
|
49
35
|
async function printHeader(longestFileLength, longestLabelLength) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
36
|
+
const longestLengths = [
|
|
37
|
+
longestFileLength,
|
|
38
|
+
longestLabelLength
|
|
39
|
+
];
|
|
40
|
+
const headerRow = [
|
|
41
|
+
"File",
|
|
42
|
+
"Size",
|
|
43
|
+
"Gzipped"
|
|
44
|
+
].reduce((prev, cur, index) => {
|
|
45
|
+
const length = longestLengths[index];
|
|
46
|
+
let curLabel = cur;
|
|
47
|
+
if (length) {
|
|
48
|
+
curLabel = cur.length < length ? cur + " ".repeat(length - cur.length) : cur;
|
|
49
|
+
}
|
|
50
|
+
return `${prev + curLabel} `;
|
|
51
|
+
}, " ");
|
|
52
|
+
_buildershared.logger.log(_chalk.default.bold.blue(headerRow));
|
|
61
53
|
}
|
|
62
54
|
async function printFileSizes(stats, distPath) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
55
|
+
const { fs, filesize, gzipSize, stripAnsi } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
56
|
+
const formatAsset = (asset) => {
|
|
57
|
+
const contents = fs.readFileSync(_path.default.join(distPath, asset.name));
|
|
58
|
+
const size = contents.length;
|
|
59
|
+
const gzippedSize = gzipSize.sync(contents);
|
|
60
|
+
return {
|
|
61
|
+
size,
|
|
62
|
+
folder: _path.default.join(_path.default.basename(distPath), _path.default.dirname(asset.name)),
|
|
63
|
+
name: _path.default.basename(asset.name),
|
|
64
|
+
gzippedSize,
|
|
65
|
+
sizeLabel: filesize(size),
|
|
66
|
+
gzipSizeLabel: getAssetColor(gzippedSize)(filesize(gzippedSize))
|
|
76
67
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return filteredAssets.map(formatAsset);
|
|
92
|
-
})
|
|
93
|
-
.reduce((single, all) => all.concat(single), []);
|
|
94
|
-
if (assets.length === 0) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
assets.sort((a, b) => b.size - a.size);
|
|
98
|
-
const longestLabelLength = Math.max(...assets.map(a => stripAnsi(a.sizeLabel).length));
|
|
99
|
-
const longestFileLength = Math.max(...assets.map(a => stripAnsi(a.folder + path_1.default.sep + a.name).length));
|
|
100
|
-
builder_shared_1.logger.info(`File sizes after production build:\n`);
|
|
101
|
-
printHeader(longestFileLength, longestLabelLength);
|
|
102
|
-
let totalSize = 0;
|
|
103
|
-
let totalGzipSize = 0;
|
|
104
|
-
assets.forEach(asset => {
|
|
105
|
-
let { sizeLabel } = asset;
|
|
106
|
-
const { name, folder, gzipSizeLabel } = asset;
|
|
107
|
-
const fileNameLength = stripAnsi(folder + path_1.default.sep + name).length;
|
|
108
|
-
const sizeLength = stripAnsi(sizeLabel).length;
|
|
109
|
-
totalSize += asset.size;
|
|
110
|
-
totalGzipSize += asset.gzippedSize;
|
|
111
|
-
if (sizeLength < longestLabelLength) {
|
|
112
|
-
const rightPadding = ' '.repeat(longestLabelLength - sizeLength);
|
|
113
|
-
sizeLabel += rightPadding;
|
|
114
|
-
}
|
|
115
|
-
let fileNameLabel = chalk_1.default.dim(asset.folder + path_1.default.sep) + chalk_1.default.cyan(asset.name);
|
|
116
|
-
if (fileNameLength < longestFileLength) {
|
|
117
|
-
const rightPadding = ' '.repeat(longestFileLength - fileNameLength);
|
|
118
|
-
fileNameLabel += rightPadding;
|
|
119
|
-
}
|
|
120
|
-
builder_shared_1.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
68
|
+
};
|
|
69
|
+
const multiStats = "stats" in stats ? stats.stats : [
|
|
70
|
+
stats
|
|
71
|
+
];
|
|
72
|
+
const assets = multiStats.map((stats2) => {
|
|
73
|
+
const origin = stats2.toJson({
|
|
74
|
+
all: false,
|
|
75
|
+
assets: true,
|
|
76
|
+
cachedAssets: true,
|
|
77
|
+
groupAssetsByInfo: false,
|
|
78
|
+
groupAssetsByPath: false,
|
|
79
|
+
groupAssetsByChunk: false,
|
|
80
|
+
groupAssetsByExtension: false,
|
|
81
|
+
groupAssetsByEmitStatus: false
|
|
121
82
|
});
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
83
|
+
const filteredAssets = origin.assets.filter((asset) => filterAsset(asset.name));
|
|
84
|
+
return filteredAssets.map(formatAsset);
|
|
85
|
+
}).reduce((single, all) => all.concat(single), []);
|
|
86
|
+
if (assets.length === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
assets.sort((a, b) => b.size - a.size);
|
|
90
|
+
const longestLabelLength = Math.max(...assets.map((a) => stripAnsi(a.sizeLabel).length));
|
|
91
|
+
const longestFileLength = Math.max(...assets.map((a) => stripAnsi(a.folder + _path.default.sep + a.name).length));
|
|
92
|
+
_buildershared.logger.info(`File sizes after production build:
|
|
93
|
+
`);
|
|
94
|
+
printHeader(longestFileLength, longestLabelLength);
|
|
95
|
+
let totalSize = 0;
|
|
96
|
+
let totalGzipSize = 0;
|
|
97
|
+
assets.forEach((asset) => {
|
|
98
|
+
let { sizeLabel } = asset;
|
|
99
|
+
const { name, folder, gzipSizeLabel } = asset;
|
|
100
|
+
const fileNameLength = stripAnsi(folder + _path.default.sep + name).length;
|
|
101
|
+
const sizeLength = stripAnsi(sizeLabel).length;
|
|
102
|
+
totalSize += asset.size;
|
|
103
|
+
totalGzipSize += asset.gzippedSize;
|
|
104
|
+
if (sizeLength < longestLabelLength) {
|
|
105
|
+
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
106
|
+
sizeLabel += rightPadding;
|
|
107
|
+
}
|
|
108
|
+
let fileNameLabel = _chalk.default.dim(asset.folder + _path.default.sep) + _chalk.default.cyan(asset.name);
|
|
109
|
+
if (fileNameLength < longestFileLength) {
|
|
110
|
+
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
111
|
+
fileNameLabel += rightPadding;
|
|
112
|
+
}
|
|
113
|
+
_buildershared.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
114
|
+
});
|
|
115
|
+
const totalSizeLabel = `${_chalk.default.bold.blue("Total size:")} ${filesize(totalSize)}`;
|
|
116
|
+
const gzippedSizeLabel = `${_chalk.default.bold.blue("Gzipped size:")} ${filesize(totalGzipSize)}`;
|
|
117
|
+
_buildershared.logger.log(`
|
|
118
|
+
${totalSizeLabel}
|
|
119
|
+
${gzippedSizeLabel}
|
|
120
|
+
`);
|
|
125
121
|
}
|
|
126
122
|
const builderPluginFileSize = () => ({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
},
|
|
123
|
+
name: "builder-plugin-file-size",
|
|
124
|
+
setup(api) {
|
|
125
|
+
api.onAfterBuild(async ({ stats }) => {
|
|
126
|
+
const config = api.getNormalizedConfig();
|
|
127
|
+
if (config.performance.printFileSize && stats) {
|
|
128
|
+
try {
|
|
129
|
+
await printFileSizes(stats, api.context.distPath);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
_buildershared.logger.error("Failed to print file size.");
|
|
132
|
+
_buildershared.logger.error(err);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
142
137
|
});
|
|
143
|
-
exports.builderPluginFileSize = builderPluginFileSize;
|
package/dist/plugins/html.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DefaultBuilderPlugin, SharedBuilderPluginAPI } from '@modern-js/builder-shared';
|
|
2
2
|
export declare const applyInjectTags: (api: SharedBuilderPluginAPI) => void;
|
|
3
|
-
export declare const builderPluginHtml: () => DefaultBuilderPlugin;
|
|
3
|
+
export declare const builderPluginHtml: () => DefaultBuilderPlugin;
|