@rsbuild/core 0.0.0-nightly-20231017024751
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/createBuilder.d.ts +2 -0
- package/dist/createBuilder.js +51 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +21 -0
- package/dist/plugins/antd.d.ts +3 -0
- package/dist/plugins/antd.js +56 -0
- package/dist/plugins/arco.d.ts +2 -0
- package/dist/plugins/arco.js +44 -0
- package/dist/plugins/asset.d.ts +2 -0
- package/dist/plugins/asset.js +36 -0
- package/dist/plugins/assetsRetry.d.ts +2 -0
- package/dist/plugins/assetsRetry.js +77 -0
- package/dist/plugins/bundleAnalyzer.d.ts +2 -0
- package/dist/plugins/bundleAnalyzer.js +72 -0
- package/dist/plugins/cache.d.ts +2 -0
- package/dist/plugins/cache.js +147 -0
- package/dist/plugins/checkSyntax.d.ts +2 -0
- package/dist/plugins/checkSyntax.js +86 -0
- package/dist/plugins/cleanOutput.d.ts +2 -0
- package/dist/plugins/cleanOutput.js +65 -0
- package/dist/plugins/define.d.ts +2 -0
- package/dist/plugins/define.js +79 -0
- package/dist/plugins/devtool.d.ts +2 -0
- package/dist/plugins/devtool.js +26 -0
- package/dist/plugins/entry.d.ts +2 -0
- package/dist/plugins/entry.js +30 -0
- package/dist/plugins/externals.d.ts +2 -0
- package/dist/plugins/externals.js +31 -0
- package/dist/plugins/fileSize.d.ts +4 -0
- package/dist/plugins/fileSize.js +188 -0
- package/dist/plugins/html.d.ts +3 -0
- package/dist/plugins/html.js +261 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +83 -0
- package/dist/plugins/inlineChunk.d.ts +2 -0
- package/dist/plugins/inlineChunk.js +95 -0
- package/dist/plugins/moment.d.ts +2 -0
- package/dist/plugins/moment.js +26 -0
- package/dist/plugins/networkPerformance.d.ts +2 -0
- package/dist/plugins/networkPerformance.js +37 -0
- package/dist/plugins/nodeAddons.d.ts +2 -0
- package/dist/plugins/nodeAddons.js +86 -0
- package/dist/plugins/performance.d.ts +5 -0
- package/dist/plugins/performance.js +49 -0
- package/dist/plugins/preloadOrPrefetch.d.ts +2 -0
- package/dist/plugins/preloadOrPrefetch.js +40 -0
- package/dist/plugins/rem.d.ts +2 -0
- package/dist/plugins/rem.js +124 -0
- package/dist/plugins/splitChunks.d.ts +4 -0
- package/dist/plugins/splitChunks.js +275 -0
- package/dist/plugins/startUrl.d.ts +3 -0
- package/dist/plugins/startUrl.js +111 -0
- package/dist/plugins/svg.d.ts +2 -0
- package/dist/plugins/svg.js +67 -0
- package/dist/plugins/target.d.ts +2 -0
- package/dist/plugins/target.js +56 -0
- package/dist/plugins/toml.d.ts +2 -0
- package/dist/plugins/toml.js +19 -0
- package/dist/plugins/wasm.d.ts +2 -0
- package/dist/plugins/wasm.js +34 -0
- package/dist/plugins/yaml.d.ts +2 -0
- package/dist/plugins/yaml.js +19 -0
- package/package.json +49 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "builderPluginCleanOutput", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return builderPluginCleanOutput;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
12
|
+
if (typeof WeakMap !== "function")
|
|
13
|
+
return null;
|
|
14
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
17
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
18
|
+
})(nodeInterop);
|
|
19
|
+
}
|
|
20
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
21
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
25
|
+
return {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
30
|
+
if (cache && cache.has(obj)) {
|
|
31
|
+
return cache.get(obj);
|
|
32
|
+
}
|
|
33
|
+
var newObj = {};
|
|
34
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
35
|
+
for (var key in obj) {
|
|
36
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
37
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
38
|
+
if (desc && (desc.get || desc.set)) {
|
|
39
|
+
Object.defineProperty(newObj, key, desc);
|
|
40
|
+
} else {
|
|
41
|
+
newObj[key] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
newObj.default = obj;
|
|
46
|
+
if (cache) {
|
|
47
|
+
cache.set(obj, newObj);
|
|
48
|
+
}
|
|
49
|
+
return newObj;
|
|
50
|
+
}
|
|
51
|
+
const builderPluginCleanOutput = () => ({
|
|
52
|
+
name: "builder-plugin-clean-output",
|
|
53
|
+
setup(api) {
|
|
54
|
+
const clean = async () => {
|
|
55
|
+
const config = api.getNormalizedConfig();
|
|
56
|
+
if (config.output.cleanDistPath) {
|
|
57
|
+
const { emptyDir } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
|
|
58
|
+
const { distPath } = api.context;
|
|
59
|
+
await emptyDir(distPath);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
api.onBeforeBuild(clean);
|
|
63
|
+
api.onBeforeStartDevServer(clean);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "builderPluginDefine", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return builderPluginDefine;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _lodash = require("@modern-js/utils/lodash");
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
13
|
+
if (typeof WeakMap !== "function")
|
|
14
|
+
return null;
|
|
15
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
18
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
19
|
+
})(nodeInterop);
|
|
20
|
+
}
|
|
21
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
22
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
26
|
+
return {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
31
|
+
if (cache && cache.has(obj)) {
|
|
32
|
+
return cache.get(obj);
|
|
33
|
+
}
|
|
34
|
+
var newObj = {};
|
|
35
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
36
|
+
for (var key in obj) {
|
|
37
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
38
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
39
|
+
if (desc && (desc.get || desc.set)) {
|
|
40
|
+
Object.defineProperty(newObj, key, desc);
|
|
41
|
+
} else {
|
|
42
|
+
newObj[key] = obj[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
newObj.default = obj;
|
|
47
|
+
if (cache) {
|
|
48
|
+
cache.set(obj, newObj);
|
|
49
|
+
}
|
|
50
|
+
return newObj;
|
|
51
|
+
}
|
|
52
|
+
const builderPluginDefine = () => ({
|
|
53
|
+
name: "builder-plugin-define",
|
|
54
|
+
async setup(api) {
|
|
55
|
+
api.modifyBundlerChain(async (chain, { env, target, CHAIN_ID, bundler }) => {
|
|
56
|
+
const { getNodeEnv, removeTailSlash, applyOptionsChain } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
|
|
57
|
+
const config = api.getNormalizedConfig();
|
|
58
|
+
const publicPath = chain.output.get("publicPath");
|
|
59
|
+
const assetPrefix = publicPath && typeof publicPath === "string" ? publicPath : config.output.assetPrefix;
|
|
60
|
+
const builtinVars = {
|
|
61
|
+
"process.env.NODE_ENV": getNodeEnv(),
|
|
62
|
+
"process.env.ASSET_PREFIX": removeTailSlash(assetPrefix)
|
|
63
|
+
};
|
|
64
|
+
const globalVars = applyOptionsChain(builtinVars, config.source.globalVars, {
|
|
65
|
+
env,
|
|
66
|
+
target
|
|
67
|
+
});
|
|
68
|
+
var _JSON_stringify;
|
|
69
|
+
const serializedVars = (0, _lodash.mapValues)(globalVars, (value) => (_JSON_stringify = JSON.stringify(value)) !== null && _JSON_stringify !== void 0 ? _JSON_stringify : "undefined");
|
|
70
|
+
const defineExprs = config.source.define;
|
|
71
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).use(bundler.DefinePlugin, [
|
|
72
|
+
{
|
|
73
|
+
...serializedVars,
|
|
74
|
+
...defineExprs
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "builderPluginDevtool", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return builderPluginDevtool;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _shared = require("@rsbuild/shared");
|
|
12
|
+
const builderPluginDevtool = () => ({
|
|
13
|
+
name: "builder-plugin-devtool",
|
|
14
|
+
setup(api) {
|
|
15
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
16
|
+
const config = api.getNormalizedConfig();
|
|
17
|
+
if (!(0, _shared.isUseJsSourceMap)(config)) {
|
|
18
|
+
chain.devtool(false);
|
|
19
|
+
} else {
|
|
20
|
+
const prodDevTool = isServer ? "source-map" : "hidden-source-map";
|
|
21
|
+
const devtool = isProd ? prodDevTool : "cheap-module-source-map";
|
|
22
|
+
chain.devtool(devtool);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "builderPluginEntry", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return builderPluginEntry;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _lodash = /* @__PURE__ */ _interop_require_default(require("@modern-js/utils/lodash"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const builderPluginEntry = () => ({
|
|
18
|
+
name: "builder-plugin-entry",
|
|
19
|
+
setup(api) {
|
|
20
|
+
api.modifyBundlerChain(async (chain) => {
|
|
21
|
+
const { entry } = api.context;
|
|
22
|
+
const { preEntry } = api.getNormalizedConfig().source;
|
|
23
|
+
Object.keys(entry).forEach((entryName) => {
|
|
24
|
+
const appendEntry = (file) => chain.entry(entryName).add(file);
|
|
25
|
+
preEntry.forEach(appendEntry);
|
|
26
|
+
_lodash.default.castArray(entry[entryName]).forEach(appendEntry);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "builderPluginExternals", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return builderPluginExternals;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function builderPluginExternals() {
|
|
12
|
+
return {
|
|
13
|
+
name: "builder-plugin-externals",
|
|
14
|
+
setup(api) {
|
|
15
|
+
api.modifyBundlerChain((chain) => {
|
|
16
|
+
const { externals } = api.getNormalizedConfig().output;
|
|
17
|
+
if (externals) {
|
|
18
|
+
chain.externals(externals);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
|
|
22
|
+
bundlerConfigs.forEach((config) => {
|
|
23
|
+
const isWebWorker = Array.isArray(config.target) ? config.target.includes("webworker") : config.target === "webworker";
|
|
24
|
+
if (isWebWorker && config.externals) {
|
|
25
|
+
delete config.externals;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
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 _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
|
21
|
+
const _chalk = /* @__PURE__ */ _interop_require_default(require("@modern-js/utils/chalk"));
|
|
22
|
+
const _shared = require("@rsbuild/shared");
|
|
23
|
+
function _interop_require_default(obj) {
|
|
24
|
+
return obj && obj.__esModule ? obj : {
|
|
25
|
+
default: obj
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
29
|
+
if (typeof WeakMap !== "function")
|
|
30
|
+
return null;
|
|
31
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
33
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
34
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
35
|
+
})(nodeInterop);
|
|
36
|
+
}
|
|
37
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
38
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
42
|
+
return {
|
|
43
|
+
default: obj
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
+
if (cache && cache.has(obj)) {
|
|
48
|
+
return cache.get(obj);
|
|
49
|
+
}
|
|
50
|
+
var newObj = {};
|
|
51
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
+
for (var key in obj) {
|
|
53
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
+
if (desc && (desc.get || desc.set)) {
|
|
56
|
+
Object.defineProperty(newObj, key, desc);
|
|
57
|
+
} else {
|
|
58
|
+
newObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
newObj.default = obj;
|
|
63
|
+
if (cache) {
|
|
64
|
+
cache.set(obj, newObj);
|
|
65
|
+
}
|
|
66
|
+
return newObj;
|
|
67
|
+
}
|
|
68
|
+
const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
69
|
+
const getAssetColor = (size) => {
|
|
70
|
+
if (size > 300 * 1e3) {
|
|
71
|
+
return _chalk.default.bold.red;
|
|
72
|
+
}
|
|
73
|
+
if (size > 100 * 1e3) {
|
|
74
|
+
return _chalk.default.yellow;
|
|
75
|
+
}
|
|
76
|
+
return _chalk.default.green;
|
|
77
|
+
};
|
|
78
|
+
async function printHeader(longestFileLength, longestLabelLength) {
|
|
79
|
+
const longestLengths = [
|
|
80
|
+
longestFileLength,
|
|
81
|
+
longestLabelLength
|
|
82
|
+
];
|
|
83
|
+
const headerRow = [
|
|
84
|
+
"File",
|
|
85
|
+
"Size",
|
|
86
|
+
"Gzipped"
|
|
87
|
+
].reduce((prev, cur, index) => {
|
|
88
|
+
const length = longestLengths[index];
|
|
89
|
+
let curLabel = cur;
|
|
90
|
+
if (length) {
|
|
91
|
+
curLabel = cur.length < length ? cur + " ".repeat(length - cur.length) : cur;
|
|
92
|
+
}
|
|
93
|
+
return `${prev + curLabel} `;
|
|
94
|
+
}, " ");
|
|
95
|
+
_shared.logger.log(_chalk.default.bold.blue(headerRow));
|
|
96
|
+
}
|
|
97
|
+
async function printFileSizes(stats, distPath) {
|
|
98
|
+
const { fs, filesize, gzipSize, stripAnsi } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
|
|
99
|
+
const formatAsset = (asset) => {
|
|
100
|
+
const contents = fs.readFileSync(_path.default.join(distPath, asset.name));
|
|
101
|
+
const size = contents.length;
|
|
102
|
+
const gzippedSize = gzipSize.sync(contents);
|
|
103
|
+
return {
|
|
104
|
+
size,
|
|
105
|
+
folder: _path.default.join(_path.default.basename(distPath), _path.default.dirname(asset.name)),
|
|
106
|
+
name: _path.default.basename(asset.name),
|
|
107
|
+
gzippedSize,
|
|
108
|
+
sizeLabel: filesize(size, {
|
|
109
|
+
round: 1
|
|
110
|
+
}),
|
|
111
|
+
gzipSizeLabel: getAssetColor(gzippedSize)(filesize(gzippedSize, {
|
|
112
|
+
round: 1
|
|
113
|
+
}))
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const multiStats = "stats" in stats ? stats.stats : [
|
|
117
|
+
stats
|
|
118
|
+
];
|
|
119
|
+
const assets = multiStats.map((stats2) => {
|
|
120
|
+
const origin = stats2.toJson({
|
|
121
|
+
all: false,
|
|
122
|
+
assets: true,
|
|
123
|
+
cachedAssets: true,
|
|
124
|
+
groupAssetsByInfo: false,
|
|
125
|
+
groupAssetsByPath: false,
|
|
126
|
+
groupAssetsByChunk: false,
|
|
127
|
+
groupAssetsByExtension: false,
|
|
128
|
+
groupAssetsByEmitStatus: false
|
|
129
|
+
});
|
|
130
|
+
const filteredAssets = origin.assets.filter((asset) => filterAsset(asset.name));
|
|
131
|
+
return filteredAssets.map(formatAsset);
|
|
132
|
+
}).reduce((single, all) => all.concat(single), []);
|
|
133
|
+
if (assets.length === 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
assets.sort((a, b) => b.size - a.size);
|
|
137
|
+
const longestLabelLength = Math.max(...assets.map((a) => stripAnsi(a.sizeLabel).length));
|
|
138
|
+
const longestFileLength = Math.max(...assets.map((a) => stripAnsi(a.folder + _path.default.sep + a.name).length));
|
|
139
|
+
_shared.logger.info(`Production file sizes:
|
|
140
|
+
`);
|
|
141
|
+
printHeader(longestFileLength, longestLabelLength);
|
|
142
|
+
let totalSize = 0;
|
|
143
|
+
let totalGzipSize = 0;
|
|
144
|
+
assets.forEach((asset) => {
|
|
145
|
+
let { sizeLabel } = asset;
|
|
146
|
+
const { name, folder, gzipSizeLabel } = asset;
|
|
147
|
+
const fileNameLength = stripAnsi(folder + _path.default.sep + name).length;
|
|
148
|
+
const sizeLength = stripAnsi(sizeLabel).length;
|
|
149
|
+
totalSize += asset.size;
|
|
150
|
+
totalGzipSize += asset.gzippedSize;
|
|
151
|
+
if (sizeLength < longestLabelLength) {
|
|
152
|
+
const rightPadding = " ".repeat(longestLabelLength - sizeLength);
|
|
153
|
+
sizeLabel += rightPadding;
|
|
154
|
+
}
|
|
155
|
+
let fileNameLabel = _chalk.default.dim(asset.folder + _path.default.sep) + _chalk.default.cyan(asset.name);
|
|
156
|
+
if (fileNameLength < longestFileLength) {
|
|
157
|
+
const rightPadding = " ".repeat(longestFileLength - fileNameLength);
|
|
158
|
+
fileNameLabel += rightPadding;
|
|
159
|
+
}
|
|
160
|
+
_shared.logger.log(` ${fileNameLabel} ${sizeLabel} ${gzipSizeLabel}`);
|
|
161
|
+
});
|
|
162
|
+
const totalSizeLabel = `${_chalk.default.bold.blue("Total size:")} ${filesize(totalSize, {
|
|
163
|
+
round: 1
|
|
164
|
+
})}`;
|
|
165
|
+
const gzippedSizeLabel = `${_chalk.default.bold.blue("Gzipped size:")} ${filesize(totalGzipSize, {
|
|
166
|
+
round: 1
|
|
167
|
+
})}`;
|
|
168
|
+
_shared.logger.log(`
|
|
169
|
+
${totalSizeLabel}
|
|
170
|
+
${gzippedSizeLabel}
|
|
171
|
+
`);
|
|
172
|
+
}
|
|
173
|
+
const builderPluginFileSize = () => ({
|
|
174
|
+
name: "builder-plugin-file-size",
|
|
175
|
+
setup(api) {
|
|
176
|
+
api.onAfterBuild(async ({ stats }) => {
|
|
177
|
+
const config = api.getNormalizedConfig();
|
|
178
|
+
if (config.performance.printFileSize && stats) {
|
|
179
|
+
try {
|
|
180
|
+
await printFileSizes(stats, api.context.distPath);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
_shared.logger.error("Failed to print file size.");
|
|
183
|
+
_shared.logger.error(err);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|