@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.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/createBuilder.d.ts +1 -1
  3. package/dist/createBuilder.js +48 -38
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +24 -8
  6. package/dist/plugins/antd.d.ts +1 -1
  7. package/dist/plugins/antd.js +52 -30
  8. package/dist/plugins/arco.d.ts +1 -1
  9. package/dist/plugins/arco.js +43 -35
  10. package/dist/plugins/asset.d.ts +1 -1
  11. package/dist/plugins/asset.js +29 -25
  12. package/dist/plugins/assetsRetry.d.ts +1 -1
  13. package/dist/plugins/assetsRetry.js +34 -51
  14. package/dist/plugins/bundleAnalyzer.d.ts +1 -1
  15. package/dist/plugins/bundleAnalyzer.js +29 -50
  16. package/dist/plugins/cache.d.ts +1 -1
  17. package/dist/plugins/cache.js +68 -87
  18. package/dist/plugins/checkSyntax.d.ts +1 -1
  19. package/dist/plugins/checkSyntax.js +40 -54
  20. package/dist/plugins/cleanOutput.d.ts +1 -1
  21. package/dist/plugins/cleanOutput.js +22 -38
  22. package/dist/plugins/devtool.d.ts +1 -1
  23. package/dist/plugins/devtool.js +23 -21
  24. package/dist/plugins/entry.d.ts +1 -1
  25. package/dist/plugins/entry.js +23 -19
  26. package/dist/plugins/externals.d.ts +1 -1
  27. package/dist/plugins/externals.js +28 -25
  28. package/dist/plugins/fileSize.d.ts +1 -1
  29. package/dist/plugins/fileSize.js +124 -130
  30. package/dist/plugins/html.d.ts +1 -1
  31. package/dist/plugins/html.js +203 -206
  32. package/dist/plugins/index.d.ts +1 -1
  33. package/dist/plugins/index.js +40 -53
  34. package/dist/plugins/inlineChunk.d.ts +1 -1
  35. package/dist/plugins/inlineChunk.js +50 -59
  36. package/dist/plugins/moment.d.ts +1 -1
  37. package/dist/plugins/moment.js +23 -20
  38. package/dist/plugins/rem.d.ts +1 -1
  39. package/dist/plugins/rem.js +74 -97
  40. package/dist/plugins/sourceBuild.d.ts +12 -12
  41. package/dist/plugins/sourceBuild.js +125 -109
  42. package/dist/plugins/splitChunks.d.ts +1 -1
  43. package/dist/plugins/splitChunks.js +206 -229
  44. package/dist/plugins/startUrl.d.ts +1 -1
  45. package/dist/plugins/startUrl.js +62 -78
  46. package/dist/plugins/svg.d.ts +1 -1
  47. package/dist/plugins/svg.js +64 -81
  48. package/dist/plugins/target.d.ts +1 -1
  49. package/dist/plugins/target.js +52 -31
  50. package/dist/plugins/toml.d.ts +1 -1
  51. package/dist/plugins/toml.js +16 -15
  52. package/dist/plugins/tsChecker.d.ts +1 -1
  53. package/dist/plugins/tsChecker.js +69 -92
  54. package/dist/plugins/wasm.d.ts +1 -1
  55. package/dist/plugins/wasm.js +31 -32
  56. package/dist/plugins/yaml.d.ts +1 -1
  57. package/dist/plugins/yaml.js +16 -15
  58. package/package.json +11 -9
@@ -1,143 +1,137 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.builderPluginFileSize = exports.filterAsset = void 0;
30
- /**
31
- * modified from https://github.com/facebook/create-react-app
32
- * license at https://github.com/facebook/create-react-app/blob/master/LICENSE
33
- */
34
- const path_1 = __importDefault(require("path"));
35
- const chalk_1 = __importDefault(require("@modern-js/utils/chalk"));
36
- const builder_shared_1 = require("@modern-js/builder-shared");
37
- /** Filter source map and license files */
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
- if (size > 300 * 1000) {
42
- return chalk_1.default.bold.red;
43
- }
44
- if (size > 100 * 1000) {
45
- return chalk_1.default.yellow;
46
- }
47
- return chalk_1.default.green;
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
- const longestLengths = [longestFileLength, longestLabelLength];
51
- const headerRow = ['File', 'Size', 'Gzipped'].reduce((prev, cur, index) => {
52
- const length = longestLengths[index];
53
- let curLabel = cur;
54
- if (length) {
55
- curLabel =
56
- cur.length < length ? cur + ' '.repeat(length - cur.length) : cur;
57
- }
58
- return `${prev + curLabel} `;
59
- }, ' ');
60
- builder_shared_1.logger.log(chalk_1.default.bold.blue(headerRow));
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
- const { fs, filesize, gzipSize, stripAnsi } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
64
- const formatAsset = (asset) => {
65
- const contents = fs.readFileSync(path_1.default.join(distPath, asset.name));
66
- const size = contents.length;
67
- const gzippedSize = gzipSize.sync(contents);
68
- return {
69
- size,
70
- folder: path_1.default.join(path_1.default.basename(distPath), path_1.default.dirname(asset.name)),
71
- name: path_1.default.basename(asset.name),
72
- gzippedSize,
73
- sizeLabel: filesize(size),
74
- gzipSizeLabel: getAssetColor(gzippedSize)(filesize(gzippedSize)),
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
- const multiStats = 'stats' in stats ? stats.stats : [stats];
78
- const assets = multiStats
79
- .map(stats => {
80
- const origin = stats.toJson({
81
- all: false,
82
- assets: true,
83
- cachedAssets: true,
84
- groupAssetsByInfo: false,
85
- groupAssetsByPath: false,
86
- groupAssetsByChunk: false,
87
- groupAssetsByExtension: false,
88
- groupAssetsByEmitStatus: false,
89
- });
90
- const filteredAssets = origin.assets.filter(asset => (0, exports.filterAsset)(asset.name));
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 totalSizeLabel = `${chalk_1.default.bold.blue('Total size:')} ${filesize(totalSize)}`;
123
- const gzippedSizeLabel = `${chalk_1.default.bold.blue('Gzipped size:')} ${filesize(totalGzipSize)}`;
124
- builder_shared_1.logger.log(`\n ${totalSizeLabel}\n ${gzippedSizeLabel}\n`);
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
- name: 'builder-plugin-file-size',
128
- setup(api) {
129
- api.onAfterBuild(async ({ stats }) => {
130
- const config = api.getNormalizedConfig();
131
- if (config.performance.printFileSize && stats) {
132
- try {
133
- await printFileSizes(stats, api.context.distPath);
134
- }
135
- catch (err) {
136
- builder_shared_1.logger.error('Failed to print file size.');
137
- builder_shared_1.logger.error(err);
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;
@@ -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;