@unpackjs/core 2.4.1 → 2.4.2
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/dist/index.cjs +2028 -196
- package/dist/index.js +1876 -39
- package/dist/lightningcssLoader.mjs +18 -0
- package/dist/typedCssModulesLoader.mjs +139 -0
- package/{dist → dist-types}/bundler-config/cache.d.ts +1 -1
- package/dist-types/bundler-config/cache.d.ts.map +1 -0
- package/{dist → dist-types}/bundler-config/chunkSplit.d.ts +1 -1
- package/dist-types/bundler-config/chunkSplit.d.ts.map +1 -0
- package/{dist → dist-types}/bundler-config/css.d.ts +1 -1
- package/dist-types/bundler-config/css.d.ts.map +1 -0
- package/{dist → dist-types}/bundler-config/experimentCss.d.ts +1 -1
- package/dist-types/bundler-config/experimentCss.d.ts.map +1 -0
- package/{dist → dist-types}/bundler-config/index.d.ts +1 -1
- package/dist-types/bundler-config/index.d.ts.map +1 -0
- package/{dist/lightningcss/loader.d.ts → dist-types/bundler-config/loaders/lightningcssLoader.d.ts} +2 -2
- package/dist-types/bundler-config/loaders/lightningcssLoader.d.ts.map +1 -0
- package/dist-types/bundler-config/loaders/typedCssModulesLoader.d.ts +6 -0
- package/dist-types/bundler-config/loaders/typedCssModulesLoader.d.ts.map +1 -0
- package/{dist/bundler-config → dist-types/bundler-config/plugins}/jsMinify.d.ts +1 -1
- package/dist-types/bundler-config/plugins/jsMinify.d.ts.map +1 -0
- package/{dist/lightningcss/minimizer.d.ts → dist-types/bundler-config/plugins/lightningcssMinify.d.ts} +2 -3
- package/dist-types/bundler-config/plugins/lightningcssMinify.d.ts.map +1 -0
- package/{dist/bundler-config/oxlint/plugin.d.ts → dist-types/bundler-config/plugins/oxlint/index.d.ts} +1 -1
- package/dist-types/bundler-config/plugins/oxlint/index.d.ts.map +1 -0
- package/dist-types/bundler-config/plugins/progress/helpers.d.ts.map +1 -0
- package/{dist/bundler-config → dist-types/bundler-config/plugins}/progress/rspack.d.ts +1 -1
- package/dist-types/bundler-config/plugins/progress/rspack.d.ts.map +1 -0
- package/{dist/bundler-config → dist-types/bundler-config/plugins}/progress/webpack.d.ts +1 -1
- package/dist-types/bundler-config/plugins/progress/webpack.d.ts.map +1 -0
- package/{dist/typed-css-modules/plugin.d.ts → dist-types/bundler-config/plugins/typedCssModules.d.ts} +2 -2
- package/dist-types/bundler-config/plugins/typedCssModules.d.ts.map +1 -0
- package/{dist → dist-types}/config.d.ts +1 -1
- package/dist-types/config.d.ts.map +1 -0
- package/{dist → dist-types}/createUnpack.d.ts +1 -1
- package/{dist → dist-types}/createUnpack.d.ts.map +1 -1
- package/{dist → dist-types}/index.d.ts +1 -1
- package/{dist → dist-types}/index.d.ts.map +1 -1
- package/dist-types/logger.d.ts +3 -0
- package/{dist → dist-types}/logger.d.ts.map +1 -1
- package/{dist → dist-types}/plugin.d.ts +1 -1
- package/{dist → dist-types}/plugin.d.ts.map +1 -1
- package/dist-types/run/build.d.ts +3 -0
- package/{dist → dist-types}/run/build.d.ts.map +1 -1
- package/{dist → dist-types}/run/dev.d.ts +1 -1
- package/{dist → dist-types}/run/dev.d.ts.map +1 -1
- package/{dist → dist-types}/types/config.d.ts +1 -1
- package/{dist → dist-types}/types/config.d.ts.map +1 -1
- package/{dist → dist-types}/types/index.d.ts +1 -0
- package/{dist → dist-types}/types/index.d.ts.map +1 -1
- package/{dist → dist-types}/utils.d.ts +5 -1
- package/dist-types/utils.d.ts.map +1 -0
- package/package.json +6 -37
- package/dist/bundler-config/cache.cjs +0 -114
- package/dist/bundler-config/cache.d.ts.map +0 -1
- package/dist/bundler-config/cache.js +0 -72
- package/dist/bundler-config/chunkSplit.cjs +0 -192
- package/dist/bundler-config/chunkSplit.d.ts.map +0 -1
- package/dist/bundler-config/chunkSplit.js +0 -150
- package/dist/bundler-config/css.cjs +0 -189
- package/dist/bundler-config/css.d.ts.map +0 -1
- package/dist/bundler-config/css.js +0 -149
- package/dist/bundler-config/experimentCss.cjs +0 -214
- package/dist/bundler-config/experimentCss.d.ts.map +0 -1
- package/dist/bundler-config/experimentCss.js +0 -175
- package/dist/bundler-config/helpers.cjs +0 -77
- package/dist/bundler-config/helpers.js +0 -31
- package/dist/bundler-config/index.cjs +0 -309
- package/dist/bundler-config/index.d.ts.map +0 -1
- package/dist/bundler-config/index.js +0 -262
- package/dist/bundler-config/jsMinify.cjs +0 -113
- package/dist/bundler-config/jsMinify.d.ts.map +0 -1
- package/dist/bundler-config/jsMinify.js +0 -71
- package/dist/bundler-config/oxlint/plugin.cjs +0 -143
- package/dist/bundler-config/oxlint/plugin.d.ts.map +0 -1
- package/dist/bundler-config/oxlint/plugin.js +0 -104
- package/dist/bundler-config/progress/helpers.cjs +0 -126
- package/dist/bundler-config/progress/helpers.d.ts.map +0 -1
- package/dist/bundler-config/progress/helpers.js +0 -81
- package/dist/bundler-config/progress/rspack.cjs +0 -70
- package/dist/bundler-config/progress/rspack.d.ts.map +0 -1
- package/dist/bundler-config/progress/rspack.js +0 -38
- package/dist/bundler-config/progress/webpack.cjs +0 -87
- package/dist/bundler-config/progress/webpack.d.ts.map +0 -1
- package/dist/bundler-config/progress/webpack.js +0 -45
- package/dist/colors.cjs +0 -82
- package/dist/colors.js +0 -40
- package/dist/config.cjs +0 -148
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -101
- package/dist/constants.cjs +0 -122
- package/dist/constants.js +0 -51
- package/dist/createUnpack.cjs +0 -107
- package/dist/createUnpack.js +0 -75
- package/dist/fs.cjs +0 -91
- package/dist/fs.js +0 -34
- package/dist/global.cjs +0 -36
- package/dist/global.js +0 -4
- package/dist/lightningcss/loader.cjs +0 -57
- package/dist/lightningcss/loader.d.ts.map +0 -1
- package/dist/lightningcss/loader.js +0 -25
- package/dist/lightningcss/minimizer.cjs +0 -94
- package/dist/lightningcss/minimizer.d.ts.map +0 -1
- package/dist/lightningcss/minimizer.js +0 -59
- package/dist/loadEnv.cjs +0 -122
- package/dist/loadEnv.js +0 -80
- package/dist/loadingAnimation.cjs +0 -76
- package/dist/loadingAnimation.js +0 -44
- package/dist/logger.cjs +0 -116
- package/dist/logger.d.ts +0 -3
- package/dist/logger.js +0 -74
- package/dist/openBrowser.cjs +0 -89
- package/dist/openBrowser.js +0 -49
- package/dist/plugin.cjs +0 -42
- package/dist/plugin.js +0 -10
- package/dist/prebundleDeps.cjs +0 -349
- package/dist/prebundleDeps.js +0 -303
- package/dist/progressBar.cjs +0 -66
- package/dist/progressBar.js +0 -34
- package/dist/reporter.cjs +0 -164
- package/dist/reporter.js +0 -120
- package/dist/run/build.cjs +0 -68
- package/dist/run/build.d.ts +0 -3
- package/dist/run/build.js +0 -26
- package/dist/run/dev.cjs +0 -118
- package/dist/run/dev.js +0 -75
- package/dist/run/index.cjs +0 -69
- package/dist/run/index.js +0 -4
- package/dist/typed-css-modules/loader.cjs +0 -141
- package/dist/typed-css-modules/loader.d.ts +0 -8
- package/dist/typed-css-modules/loader.d.ts.map +0 -1
- package/dist/typed-css-modules/loader.js +0 -92
- package/dist/typed-css-modules/plugin.cjs +0 -118
- package/dist/typed-css-modules/plugin.d.ts.map +0 -1
- package/dist/typed-css-modules/plugin.js +0 -75
- package/dist/typed-css-modules/utils.cjs +0 -46
- package/dist/typed-css-modules/utils.d.ts +0 -6
- package/dist/typed-css-modules/utils.d.ts.map +0 -1
- package/dist/typed-css-modules/utils.js +0 -14
- package/dist/types/chunkSplit.cjs +0 -18
- package/dist/types/chunkSplit.js +0 -2
- package/dist/types/config.cjs +0 -18
- package/dist/types/config.js +0 -2
- package/dist/types/index.cjs +0 -96
- package/dist/types/index.js +0 -7
- package/dist/types/lightningcss.cjs +0 -18
- package/dist/types/lightningcss.js +0 -2
- package/dist/types/logger.cjs +0 -45
- package/dist/types/logger.js +0 -13
- package/dist/types/oxc.cjs +0 -18
- package/dist/types/oxc.js +0 -2
- package/dist/types/plugin.cjs +0 -18
- package/dist/types/plugin.js +0 -2
- package/dist/utils.cjs +0 -346
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -204
- package/dist/watchFiles.cjs +0 -69
- package/dist/watchFiles.js +0 -27
- /package/dist/{bundler-config/oxlint/.oxlintrc.json → .oxlintrc.json} +0 -0
- /package/{dist → dist-types}/bundler-config/helpers.d.ts +0 -0
- /package/{dist → dist-types}/bundler-config/helpers.d.ts.map +0 -0
- /package/{dist/bundler-config → dist-types/bundler-config/plugins}/progress/helpers.d.ts +0 -0
- /package/{dist → dist-types}/colors.d.ts +0 -0
- /package/{dist → dist-types}/colors.d.ts.map +0 -0
- /package/{dist → dist-types}/constants.d.ts +0 -0
- /package/{dist → dist-types}/constants.d.ts.map +0 -0
- /package/{dist → dist-types}/fs.d.ts +0 -0
- /package/{dist → dist-types}/fs.d.ts.map +0 -0
- /package/{dist → dist-types}/global.d.ts +0 -0
- /package/{dist → dist-types}/global.d.ts.map +0 -0
- /package/{dist → dist-types}/loadEnv.d.ts +0 -0
- /package/{dist → dist-types}/loadEnv.d.ts.map +0 -0
- /package/{dist → dist-types}/loadingAnimation.d.ts +0 -0
- /package/{dist → dist-types}/loadingAnimation.d.ts.map +0 -0
- /package/{dist → dist-types}/openBrowser.d.ts +0 -0
- /package/{dist → dist-types}/openBrowser.d.ts.map +0 -0
- /package/{dist → dist-types}/prebundleDeps.d.ts +0 -0
- /package/{dist → dist-types}/prebundleDeps.d.ts.map +0 -0
- /package/{dist → dist-types}/progressBar.d.ts +0 -0
- /package/{dist → dist-types}/progressBar.d.ts.map +0 -0
- /package/{dist → dist-types}/reporter.d.ts +0 -0
- /package/{dist → dist-types}/reporter.d.ts.map +0 -0
- /package/{dist → dist-types}/run/index.d.ts +0 -0
- /package/{dist → dist-types}/run/index.d.ts.map +0 -0
- /package/{dist → dist-types}/types/chunkSplit.d.ts +0 -0
- /package/{dist → dist-types}/types/chunkSplit.d.ts.map +0 -0
- /package/{dist → dist-types}/types/lightningcss.d.ts +0 -0
- /package/{dist → dist-types}/types/lightningcss.d.ts.map +0 -0
- /package/{dist → dist-types}/types/logger.d.ts +0 -0
- /package/{dist → dist-types}/types/logger.d.ts.map +0 -0
- /package/{dist → dist-types}/types/oxc.d.ts +0 -0
- /package/{dist → dist-types}/types/oxc.d.ts.map +0 -0
- /package/{dist → dist-types}/types/plugin.d.ts +0 -0
- /package/{dist → dist-types}/types/plugin.d.ts.map +0 -0
- /package/{dist → dist-types}/watchFiles.d.ts +0 -0
- /package/{dist → dist-types}/watchFiles.d.ts.map +0 -0
package/dist/index.js
CHANGED
|
@@ -1,47 +1,1884 @@
|
|
|
1
|
-
import 'module';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import __rslib_shim_module__ from 'module';
|
|
2
|
+
let require = __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
+
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
|
+
import { dirname as __webpack_dirname__ } from "node:path";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__compiled_webpack_bundle_analyzer_index_js_1177eada__ from "../compiled/webpack-bundle-analyzer/index.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__compiled_webpack_merge_index_js_efd91626__ from "../compiled/webpack-merge/index.js";
|
|
7
|
+
import { experiments, rspack } from "@rspack/core";
|
|
8
|
+
import html_webpack_plugin from "html-webpack-plugin";
|
|
9
|
+
import webpack from "webpack";
|
|
10
|
+
import picocolors from "picocolors";
|
|
11
|
+
import node_fs from "node:fs";
|
|
12
|
+
import node_path, { isAbsolute, join, sep } from "node:path";
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
import { createJiti } from "jiti";
|
|
15
|
+
import node_readline from "node:readline";
|
|
16
|
+
import node_net from "node:net";
|
|
17
|
+
import node_os from "node:os";
|
|
18
|
+
import portfinder from "portfinder";
|
|
19
|
+
import { browserslistToTargets, transform } from "lightningcss";
|
|
20
|
+
import copy_webpack_plugin from "copy-webpack-plugin";
|
|
21
|
+
import json5 from "json5";
|
|
22
|
+
import { expand } from "dotenv-expand";
|
|
23
|
+
import { TsCheckerRspackPlugin } from "ts-checker-rspack-plugin";
|
|
24
|
+
import node_assert from "node:assert";
|
|
25
|
+
import mini_css_extract_plugin from "mini-css-extract-plugin";
|
|
26
|
+
import { glob, globSync } from "tinyglobby";
|
|
27
|
+
import typed_css_modules from "typed-css-modules";
|
|
28
|
+
import { minify } from "oxc-minify";
|
|
29
|
+
import { Buffer as external_node_buffer_Buffer } from "node:buffer";
|
|
30
|
+
import { exec, spawn } from "node:child_process";
|
|
31
|
+
import { promisify } from "node:util";
|
|
32
|
+
import node_zlib from "node:zlib";
|
|
33
|
+
import open_0 from "open";
|
|
34
|
+
import cors from "cors";
|
|
35
|
+
import express from "express";
|
|
36
|
+
import webpack_dev_server from "webpack-dev-server";
|
|
37
|
+
import chokidar from "chokidar";
|
|
38
|
+
var LogColor, __webpack_modules__ = {
|
|
39
|
+
"compiled/webpack-bundle-analyzer": function(module) {
|
|
40
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__compiled_webpack_bundle_analyzer_index_js_1177eada__;
|
|
19
41
|
},
|
|
20
|
-
"
|
|
21
|
-
module.exports =
|
|
22
|
-
},
|
|
23
|
-
"html-webpack-plugin": function(module) {
|
|
24
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_html_webpack_plugin_e07f62c9__;
|
|
25
|
-
},
|
|
26
|
-
webpack: function(module) {
|
|
27
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_webpack__;
|
|
42
|
+
"compiled/webpack-merge": function(module) {
|
|
43
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__compiled_webpack_merge_index_js_efd91626__;
|
|
28
44
|
}
|
|
29
|
-
};
|
|
30
|
-
var __webpack_module_cache__ = {};
|
|
45
|
+
}, __webpack_module_cache__ = {};
|
|
31
46
|
function __webpack_require__(moduleId) {
|
|
32
47
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
33
48
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
34
49
|
var module = __webpack_module_cache__[moduleId] = {
|
|
35
50
|
exports: {}
|
|
36
51
|
};
|
|
37
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
53
|
+
}
|
|
54
|
+
let colors = {
|
|
55
|
+
...picocolors,
|
|
56
|
+
rainbow: (input)=>{
|
|
57
|
+
let isWord = (char)=>!/[\s\n]/.test(char), chars = [
|
|
58
|
+
...input
|
|
59
|
+
], steps = chars.filter(isWord).length, r = 97, g = 193, b = 198, rStep = -49 / steps, gStep = -81 / steps, bStep = 0 / steps, output = '';
|
|
60
|
+
for (let char of chars)isWord(char) && (r += rStep, g += gStep, b += bStep), output += `\x1b[38;2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m${char}\x1b[39m`;
|
|
61
|
+
return output;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var logger_LogColor = ((LogColor = {}).error = "red", LogColor.warn = "yellow", LogColor.info = "cyan", LogColor.ready = "green", LogColor.event = "magenta", LogColor.wait = "blue", LogColor.debug = "dim", LogColor);
|
|
65
|
+
let CSS_MODULES_LOCAL_IDENT_NAME = '[path][name]__[local]--[hash:5]', CSS_MODULES_REGEX = /\.module\.\w+$/i, DEV_DEFAULT_FILENAME = {
|
|
66
|
+
js: 'js/[name].js',
|
|
67
|
+
jsAsync: 'js/async/[name].js',
|
|
68
|
+
css: 'css/[name].css',
|
|
69
|
+
cssAsync: 'css/async/[name].css'
|
|
70
|
+
}, PROD_DEFAULT_FILENAME = {
|
|
71
|
+
js: 'js/[name].[contenthash:8].js',
|
|
72
|
+
jsAsync: 'js/async/[name].[contenthash:8].js',
|
|
73
|
+
css: 'css/[name].[contenthash:8].css',
|
|
74
|
+
cssAsync: 'css/async/[name].[contenthash:8].css'
|
|
75
|
+
}, EXPORT_LOCALS_CONVENTION = 'camel-case-only', TEMP_DIR = 'node_modules/.unpack', NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/, CSS_NAMED_EXPORT = !1, THREAD_OPTIONS = {
|
|
76
|
+
workers: 2
|
|
77
|
+
}, DEFAULT_DEV_HOST = '0.0.0.0', DEFAULT_BROWSERSLIST = [
|
|
78
|
+
'chrome >= 107',
|
|
79
|
+
'edge >= 107',
|
|
80
|
+
'firefox >= 104',
|
|
81
|
+
'safari >= 16'
|
|
82
|
+
], DEFAULT_ES_TARGET = 'es2022', DEFAULT_LIGHTNINGCSS_TARGET = browserslistToTargets(DEFAULT_BROWSERSLIST.map((item)=>item.replace(' >= ', ' '))), TEMPLATE_CONTENT = ({ title = '', headTag = '', mountId = '' })=>`<!DOCTYPE html>
|
|
83
|
+
<html lang="en">
|
|
84
|
+
|
|
85
|
+
<head>
|
|
86
|
+
<meta charset="UTF-8" />
|
|
87
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
88
|
+
<title>
|
|
89
|
+
${title}
|
|
90
|
+
</title>
|
|
91
|
+
${headTag}
|
|
92
|
+
</head>
|
|
93
|
+
|
|
94
|
+
<body>
|
|
95
|
+
<div id="${mountId}"></div>
|
|
96
|
+
</body>
|
|
97
|
+
|
|
98
|
+
</html>`;
|
|
99
|
+
var utils_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
100
|
+
let { merge } = __webpack_require__("compiled/webpack-merge"), getNodeEnv = ()=>process.env.NODE_ENV, setNodeEnv = (env)=>{
|
|
101
|
+
process.env.NODE_ENV = env;
|
|
102
|
+
}, setDevServer = (isDevServer)=>{
|
|
103
|
+
process.env.DEV_SERVER = isDevServer ? 'true' : 'false';
|
|
104
|
+
}, isDev = ()=>'development' === getNodeEnv(), utils_isDevServer = ()=>'true' === process.env.DEV_SERVER, isWatch = ()=>isDev() && !utils_isDevServer(), isProd = ()=>'production' === getNodeEnv(), isWin = ()=>'win32' === process.platform, isString = (str)=>'string' == typeof str, isBoolean = (bool)=>'boolean' == typeof bool, isUndefined = (obj)=>void 0 === obj, isFunction = (func)=>'function' == typeof func, isObject = (obj)=>null !== obj && 'object' == typeof obj, isPlainObject = (obj)=>isObject(obj) && '[object Object]' === Object.prototype.toString.call(obj), isRegExp = (obj)=>'[object RegExp]' === Object.prototype.toString.call(obj), prettyTime = (seconds)=>{
|
|
105
|
+
let toFixed = (num, len)=>{
|
|
106
|
+
let factor = 10 ** len;
|
|
107
|
+
return Math.floor(num * factor) / factor;
|
|
108
|
+
};
|
|
109
|
+
return seconds < 1 ? `${toFixed(1000 * seconds, 0)}ms` : seconds < 60 ? `${toFixed(seconds, 2)}s` : `${toFixed(seconds / 60, 2)}m`;
|
|
110
|
+
}, getValueByPath = (target, pathArray, defaultValue)=>{
|
|
111
|
+
let current = target;
|
|
112
|
+
for(let i = 0; i < pathArray.length - 1; i++){
|
|
113
|
+
let currKey = pathArray[i];
|
|
114
|
+
current[currKey] && 'object' == typeof current[currKey] || (current[currKey] = 'string' == typeof pathArray[i + 1] ? {} : []), current = current[currKey];
|
|
115
|
+
}
|
|
116
|
+
let lastKey = pathArray.at(-1);
|
|
117
|
+
return void 0 === current[lastKey] && (current[lastKey] = defaultValue), current[lastKey];
|
|
118
|
+
}, setValueByPath = (target, pathArray, value)=>{
|
|
119
|
+
let current = target;
|
|
120
|
+
for(let i = 0; i < pathArray.length - 1; i++){
|
|
121
|
+
let currKey = pathArray[i];
|
|
122
|
+
current[currKey] && 'object' == typeof current[currKey] || (current[currKey] = 'string' == typeof pathArray[i + 1] ? {} : []), current = current[currKey];
|
|
123
|
+
}
|
|
124
|
+
current[pathArray.at(-1)] = value;
|
|
125
|
+
}, getPort = (startPort = 45678)=>new Promise((resolve)=>{
|
|
126
|
+
portfinder.getPort({
|
|
127
|
+
port: startPort
|
|
128
|
+
}, (_, port)=>{
|
|
129
|
+
resolve(port);
|
|
130
|
+
});
|
|
131
|
+
}), getCompiledPkgPath = (packageName)=>node_path.join(utils_dirname, '../compiled', packageName), getUserDepPath = (root, deps)=>{
|
|
132
|
+
for (let dep of Array.isArray(deps) ? deps : [
|
|
133
|
+
deps
|
|
134
|
+
]){
|
|
135
|
+
let absPath = node_path.resolve(root, 'node_modules', dep);
|
|
136
|
+
if (node_fs.existsSync(absPath)) return absPath;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
function getTime() {
|
|
140
|
+
let now = new Date(), hours = String(now.getHours()).padStart(2, '0'), minutes = String(now.getMinutes()).padStart(2, '0'), seconds = String(now.getSeconds()).padStart(2, '0');
|
|
141
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
142
|
+
}
|
|
143
|
+
let debounce = (fn, delay)=>{
|
|
144
|
+
let timer = null;
|
|
145
|
+
return (...args)=>{
|
|
146
|
+
clearTimeout(timer), timer = setTimeout(()=>{
|
|
147
|
+
fn(...args);
|
|
148
|
+
}, delay);
|
|
149
|
+
};
|
|
150
|
+
}, getIpv4Interfaces = ()=>{
|
|
151
|
+
let interfaces = node_os.networkInterfaces(), ipv4Interfaces = new Map();
|
|
152
|
+
for (let key of Object.keys(interfaces))for (let detail of interfaces[key]){
|
|
153
|
+
let familyV4Value = 'string' == typeof detail.family ? 'IPv4' : 4;
|
|
154
|
+
detail.family !== familyV4Value || ipv4Interfaces.has(detail.address) || ipv4Interfaces.set(detail.address, detail);
|
|
155
|
+
}
|
|
156
|
+
return Array.from(ipv4Interfaces.values());
|
|
157
|
+
}, isLoopbackHost = (host)=>[
|
|
158
|
+
'localhost',
|
|
159
|
+
'127.0.0.1',
|
|
160
|
+
'::1',
|
|
161
|
+
'0000:0000:0000:0000:0000:0000:0000:0001'
|
|
162
|
+
].includes(host), concatUrl = ({ host, port, protocol })=>`${protocol}://${host}:${port}/`, LOCAL_LABEL = 'Local: ', NETWORK_LABEL = 'Network: ', getAddressUrls = ({ protocol = 'http', port, host })=>{
|
|
163
|
+
if (host && host !== DEFAULT_DEV_HOST) return [
|
|
164
|
+
{
|
|
165
|
+
label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL,
|
|
166
|
+
url: concatUrl({
|
|
167
|
+
port,
|
|
168
|
+
host: node_net.isIPv6(host) ? '::' === host ? '[::1]' : `[${host}]` : host,
|
|
169
|
+
protocol
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
];
|
|
173
|
+
let ipv4Interfaces = getIpv4Interfaces(), addressUrls = [], hasLocalUrl = !1;
|
|
174
|
+
for (let detail of ipv4Interfaces)if (isLoopbackHost(detail.address) || detail.internal) {
|
|
175
|
+
if (hasLocalUrl) continue;
|
|
176
|
+
addressUrls.push({
|
|
177
|
+
label: LOCAL_LABEL,
|
|
178
|
+
url: concatUrl({
|
|
179
|
+
host: 'localhost',
|
|
180
|
+
port,
|
|
181
|
+
protocol
|
|
182
|
+
})
|
|
183
|
+
}), hasLocalUrl = !0;
|
|
184
|
+
} else addressUrls.push({
|
|
185
|
+
label: NETWORK_LABEL,
|
|
186
|
+
url: concatUrl({
|
|
187
|
+
host: detail.address,
|
|
188
|
+
port,
|
|
189
|
+
protocol
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
return addressUrls;
|
|
193
|
+
}, trackPerformance = (msg)=>{
|
|
194
|
+
let k = '__unpack_last_track_time';
|
|
195
|
+
if (!global[k]) {
|
|
196
|
+
global[k] = performance.now();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
msg && logger_logger.wait(`${msg} ${colors.dim('for')} ${colors.yellow(`${(performance.now() - global[k]).toFixed(2)}ms`)}`), global[k] = performance.now();
|
|
200
|
+
}, getPathInJs = (absPath)=>JSON.stringify(absPath).slice(1, -1), mergeConfig = merge, getUserDepVersion = (root, dep)=>{
|
|
201
|
+
let depPath = getUserDepPath(root, dep);
|
|
202
|
+
if (depPath) return JSON.parse(node_fs.readFileSync(node_path.resolve(depPath, 'package.json'), 'utf-8')).version;
|
|
203
|
+
}, clearLine = ()=>{
|
|
204
|
+
process.stdout.isTTY && (process.stdout.clearLine(0), process.stdout.cursorTo(0));
|
|
205
|
+
}, logUpdate = (output)=>{
|
|
206
|
+
clearLine(), process.stdout.write(output);
|
|
207
|
+
}, isDebug = ()=>'unpack' === process.env.DEBUG, isCI = ()=>!!process.env.CI;
|
|
208
|
+
function isNodeVersionAtLeast(major, minor) {
|
|
209
|
+
let [currMajor, currMinor] = process.versions.node.split('.').map(Number);
|
|
210
|
+
return currMajor > major || currMajor === major && currMinor >= minor;
|
|
211
|
+
}
|
|
212
|
+
let isCSSModules = ({ resourcePath, modules })=>{
|
|
213
|
+
if (!1 === modules) return !1;
|
|
214
|
+
isPlainObject(modules) || (modules = {});
|
|
215
|
+
let auto = modules.auto;
|
|
216
|
+
return !1 !== auto && (isRegExp(auto) ? auto.test(resourcePath) : isFunction(auto) ? auto(resourcePath) : CSS_MODULES_REGEX.test(resourcePath));
|
|
217
|
+
}, logger_prefixes = {
|
|
218
|
+
wait: "\u25CB",
|
|
219
|
+
error: "\u2A2F",
|
|
220
|
+
warn: "\u26A0",
|
|
221
|
+
info: "\u2139",
|
|
222
|
+
ready: "\u2713",
|
|
223
|
+
event: "\xbb",
|
|
224
|
+
debug: "\u279C"
|
|
225
|
+
}, logger_logger = (()=>{
|
|
226
|
+
let logger = {
|
|
227
|
+
clear: ()=>{
|
|
228
|
+
let repeatCount = process.stdout.rows - 2;
|
|
229
|
+
console.log(repeatCount > 0 ? '\n'.repeat(repeatCount) : ''), node_readline.cursorTo(process.stdout, 0, 0), node_readline.clearScreenDown(process.stdout);
|
|
230
|
+
},
|
|
231
|
+
greet: (msg)=>{
|
|
232
|
+
let { npm_execpath, npm_lifecycle_event } = process.env;
|
|
233
|
+
(!npm_execpath || 'npx' === npm_lifecycle_event || npm_execpath.includes('npx-cli') || npm_execpath.includes('.bun') || npm_execpath.includes('yarn')) && console.log(), console.log(msg);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return Object.keys(logger_prefixes).forEach((type)=>{
|
|
237
|
+
logger[type] = (message, ...args)=>{
|
|
238
|
+
((type, message, ...args)=>{
|
|
239
|
+
let label = colors[logger_LogColor[type]](logger_prefixes[type]), text = '';
|
|
240
|
+
switch(type){
|
|
241
|
+
case 'error':
|
|
242
|
+
if (message instanceof Error) if (message.stack) {
|
|
243
|
+
let [name, ...rest] = message.stack.split('\n');
|
|
244
|
+
name.startsWith('Error: ') && (name = name.slice(7), rest = rest.map((line)=>line.slice(2))), text = `${colors.red(name)}\n${colors.dim(rest.join('\n'))}`;
|
|
245
|
+
} else text = colors.red(message.message);
|
|
246
|
+
else text = colors.red(message);
|
|
247
|
+
break;
|
|
248
|
+
case 'warn':
|
|
249
|
+
text = colors.yellow(message);
|
|
250
|
+
break;
|
|
251
|
+
case 'debug':
|
|
252
|
+
text = `${colors.dim((()=>{
|
|
253
|
+
let now = new Date(), hours = now.getHours().toString().padStart(2, '0'), minutes = now.getMinutes().toString().padStart(2, '0'), seconds = now.getSeconds().toString().padStart(2, '0');
|
|
254
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
255
|
+
})())} ${colors.magenta('debug')} ${message}`;
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
text = message;
|
|
259
|
+
}
|
|
260
|
+
('debug' !== type || isDebug()) && console.log(`${label} ${text}`, ...args);
|
|
261
|
+
})(type, message, ...args);
|
|
262
|
+
};
|
|
263
|
+
}), logger;
|
|
264
|
+
})();
|
|
265
|
+
var config_filename = __webpack_fileURLToPath__(import.meta.url);
|
|
266
|
+
async function loadConfig({ cliOptions, command }) {
|
|
267
|
+
'build' === command ? setNodeEnv((null == cliOptions ? void 0 : cliOptions.watch) ? 'development' : 'production') : (setNodeEnv('development'), setDevServer(!0));
|
|
268
|
+
let root = (null == cliOptions ? void 0 : cliOptions.root) ? node_path.resolve(cliOptions.root) : process.cwd(), configFilePath = resolveConfigPath(root, null == cliOptions ? void 0 : cliOptions.config), configExport = {};
|
|
269
|
+
if (configFilePath) {
|
|
270
|
+
if (isNodeVersionAtLeast(23, 6) || /\.(?:js|mjs|cjs)$/.test(configFilePath)) {
|
|
271
|
+
logger_logger.debug('Loading config file with native loader:', colors.dim(configFilePath));
|
|
272
|
+
try {
|
|
273
|
+
let configFileURL = pathToFileURL(configFilePath).href, exportModule = await import(`${configFileURL}?t=${Date.now()}`);
|
|
274
|
+
configExport = exportModule.default ? exportModule.default : exportModule;
|
|
275
|
+
} catch (err) {
|
|
276
|
+
throw logger_logger.error(`Failed to load config file with native loader: ${colors.dim(configFilePath)}`), err;
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
logger_logger.debug('Loading config file with jiti:', colors.dim(configFilePath));
|
|
280
|
+
try {
|
|
281
|
+
let jiti = createJiti(config_filename, {
|
|
282
|
+
moduleCache: !1,
|
|
283
|
+
interopDefault: !0,
|
|
284
|
+
nativeModules: [
|
|
285
|
+
'@rspack/core',
|
|
286
|
+
"typescript"
|
|
287
|
+
]
|
|
288
|
+
});
|
|
289
|
+
configExport = await jiti.import(configFilePath, {
|
|
290
|
+
default: !0
|
|
291
|
+
});
|
|
292
|
+
} catch (err) {
|
|
293
|
+
throw logger_logger.error(`Failed to load config file with jiti: ${colors.dim(configFilePath)}`), err;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if ('function' == typeof configExport) {
|
|
297
|
+
let params = {
|
|
298
|
+
env: getNodeEnv(),
|
|
299
|
+
command: process.argv[2]
|
|
300
|
+
};
|
|
301
|
+
if (void 0 === (configExport = await configExport(params))) throw Error('Unpack config function must return a config object.');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return (null == cliOptions ? void 0 : cliOptions.port) && setValueByPath(configExport, [
|
|
305
|
+
'server',
|
|
306
|
+
'port'
|
|
307
|
+
], cliOptions.port), (null == cliOptions ? void 0 : cliOptions.open) && setValueByPath(configExport, [
|
|
308
|
+
'server',
|
|
309
|
+
'open'
|
|
310
|
+
], cliOptions.open), (null == cliOptions ? void 0 : cliOptions.analyze) && setValueByPath(configExport, [
|
|
311
|
+
'performance',
|
|
312
|
+
'bundleAnalyze'
|
|
313
|
+
], cliOptions.analyze), (null == cliOptions ? void 0 : cliOptions.root) && setValueByPath(configExport, [
|
|
314
|
+
'root'
|
|
315
|
+
], root), configExport;
|
|
316
|
+
}
|
|
317
|
+
function defineConfig(config) {
|
|
318
|
+
return config;
|
|
319
|
+
}
|
|
320
|
+
function resolveConfigPath(root, customConfig) {
|
|
321
|
+
if (customConfig) {
|
|
322
|
+
let customConfigPath = isAbsolute(customConfig) ? customConfig : join(root, customConfig);
|
|
323
|
+
if (node_fs.existsSync(customConfigPath)) return customConfigPath;
|
|
324
|
+
logger_logger.warn(`could not find config file: ${customConfigPath}`);
|
|
325
|
+
}
|
|
326
|
+
for (let file of [
|
|
327
|
+
'unpack.config.ts',
|
|
328
|
+
'unpack.config.js',
|
|
329
|
+
'unpack.config.mjs',
|
|
330
|
+
'unpack.config.cjs',
|
|
331
|
+
'unpack.config.mts',
|
|
332
|
+
'unpack.config.cts'
|
|
333
|
+
]){
|
|
334
|
+
let configFile = join(root, file);
|
|
335
|
+
if (node_fs.existsSync(configFile)) return configFile;
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
function getNormalizedPluginsByHook(hook, plugins) {
|
|
340
|
+
let pluginMap = new Map();
|
|
341
|
+
return null == plugins || plugins.forEach((plugin)=>{
|
|
342
|
+
plugin[hook] && pluginMap.set(plugin.name, plugin);
|
|
343
|
+
}), Array.from(pluginMap.values());
|
|
344
|
+
}
|
|
345
|
+
let isFileSync = (filePath)=>{
|
|
346
|
+
try {
|
|
347
|
+
var _fs_statSync;
|
|
348
|
+
return null == (_fs_statSync = node_fs.statSync(filePath, {
|
|
349
|
+
throwIfNoEntry: !1
|
|
350
|
+
})) ? void 0 : _fs_statSync.isFile();
|
|
351
|
+
} catch (_) {
|
|
352
|
+
return !1;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
function isEmptyDir(path) {
|
|
356
|
+
let files = node_fs.readdirSync(path);
|
|
357
|
+
return 0 === files.length || 1 === files.length && '.git' === files[0];
|
|
358
|
+
}
|
|
359
|
+
let findExists = (files)=>{
|
|
360
|
+
for (let file of files)if (isFileSync(file)) return file;
|
|
361
|
+
return !1;
|
|
362
|
+
};
|
|
363
|
+
async function pathExists(path) {
|
|
364
|
+
return node_fs.promises.access(path).then(()=>!0).catch(()=>!1);
|
|
365
|
+
}
|
|
366
|
+
async function isFileExists(file) {
|
|
367
|
+
return node_fs.promises.access(file, node_fs.constants.F_OK).then(()=>!0).catch(()=>!1);
|
|
368
|
+
}
|
|
369
|
+
let removeDir = (dir)=>{
|
|
370
|
+
node_fs.rmSync(dir, {
|
|
371
|
+
recursive: !0,
|
|
372
|
+
force: !0
|
|
373
|
+
});
|
|
374
|
+
}, DOTENV_LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
375
|
+
async function getBuildDependencies(root, userBuildDependencies, envFilePaths) {
|
|
376
|
+
let rootPackageJson = node_path.join(root, 'package.json'), browserslistConfig = node_path.join(root, '.browserslistrc'), tsconfigPath = node_path.join(root, 'tsconfig.json'), buildDependencies = {};
|
|
377
|
+
await isFileExists(rootPackageJson) && (buildDependencies.packageJson = [
|
|
378
|
+
rootPackageJson
|
|
379
|
+
]), await isFileExists(tsconfigPath) && (buildDependencies.tsconfig = [
|
|
380
|
+
tsconfigPath
|
|
381
|
+
]), buildDependencies.unpackConfig = [
|
|
382
|
+
resolveConfigPath(root)
|
|
383
|
+
], await isFileExists(browserslistConfig) && (buildDependencies.browserslistrc = [
|
|
384
|
+
browserslistConfig
|
|
385
|
+
]);
|
|
386
|
+
let tailwindConfig = findExists([
|
|
387
|
+
'ts',
|
|
388
|
+
'js',
|
|
389
|
+
'cjs',
|
|
390
|
+
'mjs'
|
|
391
|
+
].map((ext)=>node_path.join(root, `tailwind.config.${ext}`)));
|
|
392
|
+
return tailwindConfig && (buildDependencies.tailwindcss = [
|
|
393
|
+
tailwindConfig
|
|
394
|
+
]), envFilePaths && envFilePaths.length > 0 && (buildDependencies.envFiles = envFilePaths), {
|
|
395
|
+
...buildDependencies,
|
|
396
|
+
userBuildDependencies
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
async function applyCacheConfig({ config, unpackConfig, envFilePaths }) {
|
|
400
|
+
var _unpackConfig_build, _unpackConfig_dev;
|
|
401
|
+
if (!(null == (_unpackConfig_build = unpackConfig.build) ? void 0 : _unpackConfig_build.cache) || utils_isDevServer() && (null == (_unpackConfig_dev = unpackConfig.dev) ? void 0 : _unpackConfig_dev.lazyCompilation)) return config;
|
|
402
|
+
let cacheConfig = isPlainObject(unpackConfig.build.cache) ? unpackConfig.build.cache : {}, isRspack = 'rspack' === unpackConfig.bundler, buildDependencies = await getBuildDependencies(unpackConfig.root, cacheConfig.buildDependencies || [], envFilePaths), cacheDirectory = cacheConfig.cacheDirectory;
|
|
403
|
+
return cacheDirectory && (cacheDirectory = node_path.isAbsolute(cacheDirectory) ? cacheDirectory : node_path.join(unpackConfig.root, cacheDirectory)), logger_logger.info('persistent cache enabled'), config = isRspack ? mergeConfig(config, {
|
|
404
|
+
cache: !0,
|
|
405
|
+
experiments: {
|
|
406
|
+
cache: {
|
|
407
|
+
type: 'persistent',
|
|
408
|
+
buildDependencies: Object.values(buildDependencies).flat(),
|
|
409
|
+
storage: {
|
|
410
|
+
type: 'filesystem',
|
|
411
|
+
directory: cacheDirectory
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}) : mergeConfig(config, {
|
|
416
|
+
cache: {
|
|
417
|
+
type: 'filesystem',
|
|
418
|
+
buildDependencies,
|
|
419
|
+
cacheDirectory
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
let MODULE_PATH_REGEX = /.*[\\/]node_modules[\\/](?!\.pnpm[\\/])(?:(@[^\\/]+)[\\/])?([^\\/]+)/, SPLIT_STRATEGY_DISPATCHER = {
|
|
424
|
+
'split-by-experience': function(ctx) {
|
|
425
|
+
let { defaultConfig, forceSplittingGroups } = ctx, experienceCacheGroup = {};
|
|
426
|
+
for (let [name, test] of Object.entries({
|
|
427
|
+
axios: /node_modules[\\/]axios(-.+)?[\\/]/,
|
|
428
|
+
polyfill: /node_modules[\\/](?:tslib|core-js|@swc[\\/]helpers)[\\/]/
|
|
429
|
+
})){
|
|
430
|
+
let key = `lib-${name}`;
|
|
431
|
+
experienceCacheGroup[key] = {
|
|
432
|
+
test,
|
|
433
|
+
priority: 0,
|
|
434
|
+
name: key
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
...defaultConfig,
|
|
439
|
+
cacheGroups: {
|
|
440
|
+
...defaultConfig.cacheGroups,
|
|
441
|
+
...experienceCacheGroup,
|
|
442
|
+
...forceSplittingGroups
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
},
|
|
446
|
+
'split-by-module': function(ctx) {
|
|
447
|
+
let { forceSplittingGroups, defaultConfig } = ctx;
|
|
448
|
+
return {
|
|
449
|
+
...defaultConfig,
|
|
450
|
+
minSize: 0,
|
|
451
|
+
maxInitialRequests: Number.POSITIVE_INFINITY,
|
|
452
|
+
cacheGroups: {
|
|
453
|
+
...defaultConfig.cacheGroups,
|
|
454
|
+
...forceSplittingGroups,
|
|
455
|
+
vendors: {
|
|
456
|
+
priority: -9,
|
|
457
|
+
test: NODE_MODULES_REGEX,
|
|
458
|
+
name: (module)=>module ? function(modulePath) {
|
|
459
|
+
let handleModuleContext = null == modulePath ? void 0 : modulePath.match(MODULE_PATH_REGEX);
|
|
460
|
+
if (!handleModuleContext) return;
|
|
461
|
+
let [, scope, name] = handleModuleContext;
|
|
462
|
+
return [
|
|
463
|
+
'npm',
|
|
464
|
+
(scope ?? '').replace('@', ''),
|
|
465
|
+
name
|
|
466
|
+
].filter(Boolean).join('.');
|
|
467
|
+
}(module.context) : void 0
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
},
|
|
472
|
+
'split-by-size': function(ctx) {
|
|
473
|
+
let { forceSplittingGroups, defaultConfig, chunkSplit } = ctx;
|
|
474
|
+
return node_assert('split-by-size' === chunkSplit.strategy), {
|
|
475
|
+
...defaultConfig,
|
|
476
|
+
minSize: chunkSplit.minSize ?? 0,
|
|
477
|
+
maxSize: chunkSplit.maxSize ?? Number.POSITIVE_INFINITY,
|
|
478
|
+
cacheGroups: {
|
|
479
|
+
...defaultConfig.cacheGroups,
|
|
480
|
+
...forceSplittingGroups
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
},
|
|
484
|
+
custom: function(ctx) {
|
|
485
|
+
let { forceSplittingGroups, defaultConfig } = ctx;
|
|
486
|
+
return {
|
|
487
|
+
...defaultConfig,
|
|
488
|
+
cacheGroups: {
|
|
489
|
+
...defaultConfig.cacheGroups,
|
|
490
|
+
...forceSplittingGroups
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
},
|
|
494
|
+
'all-in-one': function(_ctx) {
|
|
495
|
+
return !1;
|
|
496
|
+
},
|
|
497
|
+
'single-vendor': function(ctx) {
|
|
498
|
+
let { defaultConfig, forceSplittingGroups } = ctx;
|
|
499
|
+
return {
|
|
500
|
+
...defaultConfig,
|
|
501
|
+
cacheGroups: {
|
|
502
|
+
...defaultConfig.cacheGroups,
|
|
503
|
+
singleVendor: {
|
|
504
|
+
test: NODE_MODULES_REGEX,
|
|
505
|
+
priority: 0,
|
|
506
|
+
chunks: 'all',
|
|
507
|
+
name: 'vendor',
|
|
508
|
+
enforce: !0
|
|
509
|
+
},
|
|
510
|
+
...forceSplittingGroups
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
async function getEntry(root, customEntry) {
|
|
516
|
+
let entry;
|
|
517
|
+
return entry = customEntry ? node_path.resolve(root, customEntry) : (await glob('(index|Index).{js,ts,jsx,tsx}', {
|
|
518
|
+
cwd: node_path.join(root, 'src'),
|
|
519
|
+
absolute: !0
|
|
520
|
+
}))[0], node_fs.existsSync(entry) || (logger_logger.error(Error('could not find entry file')), process.exit(1)), entry;
|
|
521
|
+
}
|
|
522
|
+
let getOutputFilename = ({ type, hash, async })=>{
|
|
523
|
+
let FILENAME = isProd() && !1 !== hash ? PROD_DEFAULT_FILENAME : DEV_DEFAULT_FILENAME;
|
|
524
|
+
return async ? 'js' === type ? FILENAME.jsAsync : FILENAME.cssAsync : FILENAME[type];
|
|
525
|
+
};
|
|
526
|
+
var css_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
527
|
+
function _define_property(obj, key, value) {
|
|
528
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
529
|
+
value: value,
|
|
530
|
+
enumerable: !0,
|
|
531
|
+
configurable: !0,
|
|
532
|
+
writable: !0
|
|
533
|
+
}) : obj[key] = value, obj;
|
|
534
|
+
}
|
|
535
|
+
let statPromise = node_fs.promises.stat, DtsCreator = typed_css_modules.default || typed_css_modules;
|
|
536
|
+
async function writeFile(dtsCreator, cssFile) {
|
|
537
|
+
let content = await dtsCreator.create(cssFile, void 0, !0);
|
|
538
|
+
await content.writeFile((definition)=>`// Generated automatically, do not edit\n${definition}`);
|
|
539
|
+
}
|
|
540
|
+
async function generateTypingIfNecessary(dtsCreator, cssFile) {
|
|
541
|
+
let typingStat;
|
|
542
|
+
try {
|
|
543
|
+
typingStat = await statPromise(`${cssFile}.d.ts`);
|
|
544
|
+
} catch {
|
|
545
|
+
return writeFile(dtsCreator, cssFile);
|
|
546
|
+
}
|
|
547
|
+
if ((await statPromise(cssFile)).mtime.getTime() > typingStat.mtime.getTime()) return writeFile(dtsCreator, cssFile);
|
|
548
|
+
}
|
|
549
|
+
let typedCssModules_PLUGIN_NAME = 'TypedCssModulesPlugin';
|
|
550
|
+
class TypedCssModulesPlugin {
|
|
551
|
+
apply(compiler) {
|
|
552
|
+
compiler.hooks.run.tapPromise(typedCssModules_PLUGIN_NAME, async ()=>{
|
|
553
|
+
await this.generateCssTypings(this.useIncremental);
|
|
554
|
+
}), compiler.hooks.watchRun.tap(typedCssModules_PLUGIN_NAME, ()=>{
|
|
555
|
+
setTimeout(()=>{
|
|
556
|
+
this.generateCssTypings(this.useIncremental).catch((err)=>{
|
|
557
|
+
logger_logger.error(err.toString());
|
|
558
|
+
}).finally(()=>{
|
|
559
|
+
this.useIncremental = !0;
|
|
560
|
+
});
|
|
561
|
+
}, 100);
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
async generateCssTypings(incremental) {
|
|
565
|
+
let cssModulesFiles = (await glob(this.globPattern)).filter((file)=>{
|
|
566
|
+
var _this_userOptions;
|
|
567
|
+
return isCSSModules({
|
|
568
|
+
resourcePath: file,
|
|
569
|
+
modules: null == (_this_userOptions = this.userOptions) ? void 0 : _this_userOptions.modules
|
|
570
|
+
});
|
|
571
|
+
}), doTask = incremental ? generateTypingIfNecessary : writeFile;
|
|
572
|
+
return Promise.all(cssModulesFiles.map((file)=>doTask(this.dtsCreator, file)));
|
|
573
|
+
}
|
|
574
|
+
constructor(options){
|
|
575
|
+
_define_property(this, "dtsCreator", void 0), _define_property(this, "useIncremental", !1), _define_property(this, "globPattern", 'src/**/*.{css,less,scss}'), _define_property(this, "userOptions", void 0), this.userOptions = options, this.dtsCreator = new DtsCreator({
|
|
576
|
+
camelCase: !0,
|
|
577
|
+
namedExports: CSS_NAMED_EXPORT
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
var experimentCss_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
582
|
+
function jsMinify_define_property(obj, key, value) {
|
|
583
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
584
|
+
value: value,
|
|
585
|
+
enumerable: !0,
|
|
586
|
+
configurable: !0,
|
|
587
|
+
writable: !0
|
|
588
|
+
}) : obj[key] = value, obj;
|
|
589
|
+
}
|
|
590
|
+
let { RawSource: jsMinify_RawSource, SourceMapSource: jsMinify_SourceMapSource } = webpack.sources, isJsFile = /\.[cm]?js(\?.*)?$/i, jsMinify_PLUGIN_NAME = 'JsMinifyPlugin';
|
|
591
|
+
class JsMinifyPlugin {
|
|
592
|
+
apply(compiler) {
|
|
593
|
+
let meta = JSON.stringify({
|
|
594
|
+
name: jsMinify_PLUGIN_NAME,
|
|
595
|
+
version: "2.4.2",
|
|
596
|
+
options: this.minifyOptions
|
|
597
|
+
});
|
|
598
|
+
compiler.hooks.compilation.tap(jsMinify_PLUGIN_NAME, (compilation)=>{
|
|
599
|
+
compilation.hooks.chunkHash.tap(jsMinify_PLUGIN_NAME, (_, hash)=>hash.update(meta)), compilation.hooks.processAssets.tap({
|
|
600
|
+
name: jsMinify_PLUGIN_NAME,
|
|
601
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
|
|
602
|
+
additionalAssets: !0
|
|
603
|
+
}, ()=>this.transformAssets(compilation)), compilation.hooks.statsPrinter.tap(jsMinify_PLUGIN_NAME, (stats)=>{
|
|
604
|
+
stats.hooks.print.for('asset.info.minimized').tap(jsMinify_PLUGIN_NAME, (minimized, { green, formatFlag })=>minimized && green && formatFlag ? green(formatFlag('minimized')) : '');
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
transformAssets(compilation) {
|
|
609
|
+
let { options: { devtool } } = compilation.compiler, sourceMap = 'string' == typeof devtool && devtool.includes('source-map');
|
|
610
|
+
compilation.getAssets().filter((asset)=>!asset.info.minimized && isJsFile.test(asset.name)).map((asset)=>{
|
|
611
|
+
let { source, map } = asset.source.sourceAndMap(), { name } = asset, output = this.minify(name, Buffer.isBuffer(source) ? source.toString() : source, {
|
|
612
|
+
sourcemap: sourceMap,
|
|
613
|
+
...this.minifyOptions
|
|
614
|
+
}), newMap = null;
|
|
615
|
+
output.map && ((newMap = 'string' == typeof output.map ? JSON.parse(output.map) : output.map).sources = [
|
|
616
|
+
asset.name
|
|
617
|
+
]);
|
|
618
|
+
let newSource = sourceMap && newMap ? new jsMinify_SourceMapSource(output.code, asset.name, newMap, source, map, !0) : new jsMinify_RawSource(output.code), newInfo = {
|
|
619
|
+
...asset.info,
|
|
620
|
+
minimized: !0
|
|
621
|
+
};
|
|
622
|
+
compilation.updateAsset(asset.name, newSource, newInfo);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
constructor(options = {}){
|
|
626
|
+
jsMinify_define_property(this, "minify", void 0), jsMinify_define_property(this, "minifyOptions", void 0);
|
|
627
|
+
let { implementation, ...minifyOptions } = options;
|
|
628
|
+
this.minify = (null == implementation ? void 0 : implementation.minify) ?? minify, this.minifyOptions = minifyOptions;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function lightningcssMinify_define_property(obj, key, value) {
|
|
632
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
633
|
+
value: value,
|
|
634
|
+
enumerable: !0,
|
|
635
|
+
configurable: !0,
|
|
636
|
+
writable: !0
|
|
637
|
+
}) : obj[key] = value, obj;
|
|
638
|
+
}
|
|
639
|
+
let lightningcssMinify_PLUGIN_NAME = 'LightningcssMinifyPlugin';
|
|
640
|
+
class LightningcssMinifyPlugin {
|
|
641
|
+
apply(compiler) {
|
|
642
|
+
compiler.hooks.compilation.tap(lightningcssMinify_PLUGIN_NAME, (compilation)=>{
|
|
643
|
+
compilation.hooks.processAssets.tap({
|
|
644
|
+
name: lightningcssMinify_PLUGIN_NAME,
|
|
645
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
|
646
|
+
}, ()=>this.transformAssets(compilation)), compilation.hooks.statsPrinter.tap(lightningcssMinify_PLUGIN_NAME, (statsPrinter)=>{
|
|
647
|
+
statsPrinter.hooks.print.for('asset.info.minimized').tap(lightningcssMinify_PLUGIN_NAME, (minimized, { green, formatFlag })=>minimized && green && formatFlag ? green(formatFlag('minimized')) : '');
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
transformAssets(compilation) {
|
|
652
|
+
let { options: { devtool }, webpack: { sources: { SourceMapSource, RawSource } } } = compilation.compiler, sourceMap = 'string' == typeof devtool && devtool.includes('source-map');
|
|
653
|
+
compilation.getAssets().filter((asset)=>!asset.info.minimized && /\.css$/.test(asset.name)).map((asset)=>{
|
|
654
|
+
let { source, map } = asset.source.sourceAndMap(), sourceAsString = source.toString(), code = 'string' == typeof source ? external_node_buffer_Buffer.from(source) : source, result = this.transform({
|
|
655
|
+
filename: asset.name,
|
|
656
|
+
code,
|
|
657
|
+
minify: !0,
|
|
658
|
+
sourceMap,
|
|
659
|
+
...this.transformOptions
|
|
660
|
+
}), codeString = result.code.toString();
|
|
661
|
+
compilation.updateAsset(asset.name, sourceMap ? new SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, !0) : new RawSource(codeString), {
|
|
662
|
+
...asset.info,
|
|
663
|
+
minimized: !0
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
constructor(options = {}){
|
|
668
|
+
lightningcssMinify_define_property(this, "transform", void 0), lightningcssMinify_define_property(this, "transformOptions", void 0);
|
|
669
|
+
let { implementation, ...transformOptions } = options;
|
|
670
|
+
this.transform = (null == implementation ? void 0 : implementation.transform) ?? transform, this.transformOptions = transformOptions;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
var oxlint_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
674
|
+
function oxlint_define_property(obj, key, value) {
|
|
675
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
676
|
+
value: value,
|
|
677
|
+
enumerable: !0,
|
|
678
|
+
configurable: !0,
|
|
679
|
+
writable: !0
|
|
680
|
+
}) : obj[key] = value, obj;
|
|
681
|
+
}
|
|
682
|
+
class OxlintPlugin {
|
|
683
|
+
getGitChangedFiles() {
|
|
684
|
+
return new Promise((resolve)=>{
|
|
685
|
+
var _child_stdout;
|
|
686
|
+
let child = spawn('git', [
|
|
687
|
+
'status',
|
|
688
|
+
'--porcelain'
|
|
689
|
+
], {
|
|
690
|
+
cwd: process.cwd(),
|
|
691
|
+
stdio: 'pipe'
|
|
692
|
+
}), output = '';
|
|
693
|
+
null == (_child_stdout = child.stdout) || _child_stdout.on('data', (data)=>{
|
|
694
|
+
output += data.toString();
|
|
695
|
+
}), child.on('exit', (code)=>{
|
|
696
|
+
0 === code ? resolve(output.trim().split('\n').filter(Boolean).map((line)=>{
|
|
697
|
+
let idx = line.indexOf(' '), status = line.slice(0, idx), filePath = line.slice(idx + 1).trim();
|
|
698
|
+
return status.includes('D') ? null : ((status.startsWith('R') || status.startsWith('C')) && (filePath = filePath.split(' -> ')[1]), filePath);
|
|
699
|
+
}).filter(Boolean).map((file)=>node_path.resolve(process.cwd(), file))) : resolve([]);
|
|
700
|
+
}), child.on('error', ()=>{
|
|
701
|
+
resolve([]);
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
runOxlint(args) {
|
|
706
|
+
var _child_stdout, _child_stderr;
|
|
707
|
+
let child = spawn('npx', [
|
|
708
|
+
'--yes',
|
|
709
|
+
...args
|
|
710
|
+
], {
|
|
711
|
+
cwd: process.cwd(),
|
|
712
|
+
stdio: 'pipe',
|
|
713
|
+
shell: !0,
|
|
714
|
+
env: {
|
|
715
|
+
...process.env,
|
|
716
|
+
FORCE_COLOR: '1'
|
|
717
|
+
}
|
|
718
|
+
}), output = '';
|
|
719
|
+
null == (_child_stdout = child.stdout) || _child_stdout.on('data', (data)=>{
|
|
720
|
+
output += data.toString();
|
|
721
|
+
}), child.on('exit', (code)=>{
|
|
722
|
+
output.includes('Found 0 warnings and 0 errors') && 0 === code || process.stdout.write(output);
|
|
723
|
+
}), null == (_child_stderr = child.stderr) || _child_stderr.on('data', (data)=>{
|
|
724
|
+
process.stderr.write(data);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
apply(compiler) {
|
|
728
|
+
compiler.hooks.watchRun.tap('OxlintPlugin', ()=>{
|
|
729
|
+
this.timeoutId && clearTimeout(this.timeoutId), this.timeoutId = setTimeout(()=>{
|
|
730
|
+
let configPath = node_path.resolve(oxlint_dirname, '.oxlintrc.json');
|
|
731
|
+
this.getGitChangedFiles().then((changedFiles)=>{
|
|
732
|
+
if (changedFiles.length > 0) {
|
|
733
|
+
let args = [
|
|
734
|
+
'oxlint',
|
|
735
|
+
'-c',
|
|
736
|
+
configPath,
|
|
737
|
+
...changedFiles,
|
|
738
|
+
'--fix',
|
|
739
|
+
'--fix-suggestions'
|
|
740
|
+
];
|
|
741
|
+
this.runOxlint(args);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}, this.debounceTime);
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
constructor(){
|
|
748
|
+
oxlint_define_property(this, "timeoutId", null), oxlint_define_property(this, "debounceTime", 200);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function loadingAnimation_define_property(obj, key, value) {
|
|
752
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
753
|
+
value: value,
|
|
754
|
+
enumerable: !0,
|
|
755
|
+
configurable: !0,
|
|
756
|
+
writable: !0
|
|
757
|
+
}) : obj[key] = value, obj;
|
|
758
|
+
}
|
|
759
|
+
class LoadingAnimation {
|
|
760
|
+
getCurrentChar() {
|
|
761
|
+
let now = Date.now();
|
|
762
|
+
return now - this.lastUpdateTime >= this.interval && (this.currentIndex = (this.currentIndex + 1) % this.chars.length, this.lastUpdateTime = now), this.chars[this.currentIndex];
|
|
763
|
+
}
|
|
764
|
+
reset() {
|
|
765
|
+
this.currentIndex = 0, this.lastUpdateTime = 0;
|
|
766
|
+
}
|
|
767
|
+
constructor(){
|
|
768
|
+
loadingAnimation_define_property(this, "chars", [
|
|
769
|
+
"\u280B",
|
|
770
|
+
"\u2819",
|
|
771
|
+
"\u2839",
|
|
772
|
+
"\u2838",
|
|
773
|
+
"\u283C",
|
|
774
|
+
"\u2834",
|
|
775
|
+
"\u2826",
|
|
776
|
+
"\u2827",
|
|
777
|
+
"\u2807",
|
|
778
|
+
"\u280F"
|
|
779
|
+
]), loadingAnimation_define_property(this, "currentIndex", 0), loadingAnimation_define_property(this, "lastUpdateTime", 0), loadingAnimation_define_property(this, "interval", 150);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function progressBar_define_property(obj, key, value) {
|
|
783
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
784
|
+
value: value,
|
|
785
|
+
enumerable: !0,
|
|
786
|
+
configurable: !0,
|
|
787
|
+
writable: !0
|
|
788
|
+
}) : obj[key] = value, obj;
|
|
789
|
+
}
|
|
790
|
+
class ProgressBar {
|
|
791
|
+
update({ current: originalCurrent, message = '' }) {
|
|
792
|
+
if (isCI()) return;
|
|
793
|
+
let { columns: terminalWidth } = process.stdout, current = originalCurrent;
|
|
794
|
+
originalCurrent >= 0.98 && (current = 1);
|
|
795
|
+
let loadingChar = this.loadingAnimation.getCurrentChar(), messageWidth = terminalWidth - this.prefix.length - (1 === current ? 10 : 9);
|
|
796
|
+
logUpdate(`${loadingChar} ${this.prefix} (${Math.floor(100 * current)}%) ${colors.dim(message.slice(0, messageWidth).padEnd(messageWidth, ' '))}`);
|
|
797
|
+
}
|
|
798
|
+
done() {
|
|
799
|
+
console.log();
|
|
800
|
+
}
|
|
801
|
+
constructor(){
|
|
802
|
+
progressBar_define_property(this, "prefix", 'transforming'), progressBar_define_property(this, "loadingAnimation", new LoadingAnimation());
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
let gzip = promisify(node_zlib.gzip), numberFormatter = new Intl.NumberFormat('en', {
|
|
806
|
+
maximumFractionDigits: 2,
|
|
807
|
+
minimumFractionDigits: 2
|
|
808
|
+
}), displaySize = (bytes)=>`${numberFormatter.format(bytes / 1000)} kB`;
|
|
809
|
+
async function getCompressedSize(content) {
|
|
810
|
+
return (await gzip(content)).length;
|
|
811
|
+
}
|
|
812
|
+
async function printFileSize({ root, stats }) {
|
|
813
|
+
let chunkGroups = [
|
|
814
|
+
{
|
|
815
|
+
type: 'HTML',
|
|
816
|
+
color: 'green',
|
|
817
|
+
chunks: []
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
type: 'Assets',
|
|
821
|
+
color: 'yellow',
|
|
822
|
+
chunks: []
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
type: 'CSS',
|
|
826
|
+
color: 'magenta',
|
|
827
|
+
chunks: []
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
type: 'JS',
|
|
831
|
+
color: 'cyan',
|
|
832
|
+
chunks: []
|
|
833
|
+
}
|
|
834
|
+
], chunkGroupMap = chunkGroups.reduce((acc, cur)=>(acc[cur.type] = cur, acc), {}), compressedCount = 0, loadingAnimation = new LoadingAnimation();
|
|
835
|
+
logUpdate(`${loadingAnimation.getCurrentChar()} computing gzip size (0)...`);
|
|
836
|
+
let distPath = stats.compilation.outputOptions.path, distFolder = node_path.relative(root, distPath), origin = stats.toJson({
|
|
837
|
+
all: !1,
|
|
838
|
+
assets: !0,
|
|
839
|
+
cachedAssets: !0,
|
|
840
|
+
groupAssetsByInfo: !1,
|
|
841
|
+
groupAssetsByPath: !1,
|
|
842
|
+
groupAssetsByChunk: !1,
|
|
843
|
+
groupAssetsByExtension: !1,
|
|
844
|
+
groupAssetsByEmitStatus: !1
|
|
845
|
+
}), longest = 0, totalSize = 0, totalCompressedSize = 0;
|
|
846
|
+
await Promise.all(origin.assets.map(async (asset)=>{
|
|
847
|
+
let content = await node_fs.promises.readFile(node_path.join(distPath, asset.name)), size = content.length, compressedSize = await getCompressedSize(content);
|
|
848
|
+
totalSize += size, totalCompressedSize += compressedSize, compressedCount++, logUpdate(`${loadingAnimation.getCurrentChar()} computing gzip size (${compressedCount})...`), compressedCount === origin.assets.length && (logUpdate(`\u{2713} computed gzip size (${compressedCount})`), console.log());
|
|
849
|
+
let chunk = {
|
|
850
|
+
name: node_path.basename(asset.name),
|
|
851
|
+
path: `${distFolder}/${asset.name}`,
|
|
852
|
+
size,
|
|
853
|
+
compressedSize
|
|
854
|
+
};
|
|
855
|
+
switch(chunk.path.length > longest && (longest = chunk.path.length), node_path.extname(asset.name)){
|
|
856
|
+
case '.html':
|
|
857
|
+
chunkGroupMap.HTML.chunks.push(chunk);
|
|
858
|
+
break;
|
|
859
|
+
case '.css':
|
|
860
|
+
chunkGroupMap.CSS.chunks.push(chunk);
|
|
861
|
+
break;
|
|
862
|
+
case '.js':
|
|
863
|
+
chunkGroupMap.JS.chunks.push(chunk);
|
|
864
|
+
break;
|
|
865
|
+
default:
|
|
866
|
+
chunkGroupMap.Assets.chunks.push(chunk);
|
|
867
|
+
}
|
|
868
|
+
}));
|
|
869
|
+
let sizePad = displaySize(totalSize).length, compressPad = displaySize(totalCompressedSize).length;
|
|
870
|
+
chunkGroups.forEach((group)=>{
|
|
871
|
+
group.chunks.sort((a, b)=>a.size - b.size).forEach((chunk)=>{
|
|
872
|
+
let isLarge = 'JS' === group.type && chunk.size / 1000 > 500, relativeOutDir = node_path.dirname(chunk.path) + '/', log = colors.dim(relativeOutDir);
|
|
873
|
+
log += colors[group.color](chunk.name.padEnd(longest + 2 - relativeOutDir.length)), log += colors[isLarge ? 'yellow' : 'dim'](displaySize(chunk.size).padStart(sizePad)), chunk.compressedSize && (log += colors.dim(` \u{2502} gzip: ${displaySize(chunk.compressedSize).padStart(compressPad)}`)), console.log(log);
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
let log = colors.blue('Total'.padEnd(longest + 2));
|
|
877
|
+
log += colors.blue(displaySize(totalSize)), console.log(log += colors.dim(` \u{2502} gzip: ${displaySize(totalCompressedSize)}`));
|
|
878
|
+
}
|
|
879
|
+
function isLikelyFile(filePath) {
|
|
880
|
+
return (filePath.split(sep).pop() || '').includes('.');
|
|
881
|
+
}
|
|
882
|
+
function formatFileList(paths, rootPath) {
|
|
883
|
+
let files = paths.filter(isLikelyFile);
|
|
884
|
+
0 === files.length && (files = [
|
|
885
|
+
paths[0]
|
|
886
|
+
]);
|
|
887
|
+
let fileInfo = files.slice(0, 1).map((file)=>(function(originalFilePath, root) {
|
|
888
|
+
let prefix = root.endsWith(sep) ? root : root + sep, filePath = originalFilePath;
|
|
889
|
+
filePath.startsWith(prefix) && (filePath = filePath.slice(prefix.length));
|
|
890
|
+
let parts = filePath.split(sep).filter(Boolean);
|
|
891
|
+
return parts.length > 3 ? parts.slice(-3).join(sep) : parts.join(sep);
|
|
892
|
+
})(file, rootPath)).join(', ');
|
|
893
|
+
return files.length > 1 ? `${fileInfo} and ${files.length - 1} more` : fileInfo;
|
|
894
|
+
}
|
|
895
|
+
function printDevLog(compiler, root) {
|
|
896
|
+
let changedFiles = compiler.modifiedFiles ? Array.from(compiler.modifiedFiles) : null;
|
|
897
|
+
if (null == changedFiles ? void 0 : changedFiles.length) {
|
|
898
|
+
let fileInfo = formatFileList(changedFiles, root);
|
|
899
|
+
logger_logger.wait(`building ${colors.dim(fileInfo)}`);
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
let removedFiles = compiler.removedFiles ? Array.from(compiler.removedFiles) : null;
|
|
903
|
+
if (null == removedFiles ? void 0 : removedFiles.length) {
|
|
904
|
+
let fileInfo = formatFileList(removedFiles, root);
|
|
905
|
+
logger_logger.wait(`building ${colors.dim(`removed ${fileInfo}`)}`);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
logger_logger.wait('building...');
|
|
909
|
+
}
|
|
910
|
+
async function compileDone(compiler, stats) {
|
|
911
|
+
let compileTime = stats.toJson({
|
|
912
|
+
preset: 'errors-only',
|
|
913
|
+
timings: !0
|
|
914
|
+
}).time / 1000, root = compiler.options.context;
|
|
915
|
+
if (!stats.hasErrors()) if (isProd()) isCI() || await printFileSize({
|
|
916
|
+
root,
|
|
917
|
+
stats
|
|
918
|
+
}), logger_logger.ready(colors.green(`built in ${prettyTime(compileTime)}`));
|
|
919
|
+
else {
|
|
920
|
+
if (isDebug()) {
|
|
921
|
+
let modules = stats.compilation.modules, nodeModulesStats = new Map(), nodeModulesPath = node_path.resolve(root, 'node_modules');
|
|
922
|
+
modules.forEach((module)=>{
|
|
923
|
+
let { resource } = module;
|
|
924
|
+
if (null == resource ? void 0 : resource.includes(nodeModulesPath)) {
|
|
925
|
+
let packageName, pathParts = node_path.relative(nodeModulesPath, resource).split(sep);
|
|
926
|
+
(packageName = '.pnpm' === pathParts[0] && pathParts.length >= 4 ? pathParts[3].startsWith('@') ? `${pathParts[3]}/${pathParts[4]}` : pathParts[3] : pathParts[0].startsWith('@') ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0]) && nodeModulesStats.set(packageName, (nodeModulesStats.get(packageName) || 0) + 1);
|
|
927
|
+
}
|
|
928
|
+
}), nodeModulesStats.size > 0 && Array.from(nodeModulesStats.entries()).sort((a, b)=>a[1] - b[1]).forEach(([packageName, count])=>{
|
|
929
|
+
logger_logger.debug(`${colors.cyan(packageName)}: ${colors.yellow(count)} modules`);
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
logger_logger.ready(`built in ${prettyTime(compileTime)}${isDebug() ? ` (${stats.compilation.modules.size} modules)` : ''}`);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
let rspack_PLUGIN_NAME = 'ProgressPlugin';
|
|
936
|
+
class ProgressRspackPlugin extends rspack.ProgressPlugin {
|
|
937
|
+
apply(compiler) {
|
|
938
|
+
super.apply(compiler), compiler.hooks.watchRun.tap(rspack_PLUGIN_NAME, ()=>{
|
|
939
|
+
(!utils_isDevServer() || global.__unpack_dev_server_started) && printDevLog(compiler, compiler.options.context);
|
|
940
|
+
}), compiler.hooks.afterDone.tap(rspack_PLUGIN_NAME, async (stats)=>{
|
|
941
|
+
await compileDone(compiler, stats);
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
constructor(){
|
|
945
|
+
var key, value;
|
|
946
|
+
super((percentage, msg, ...args)=>{
|
|
947
|
+
isProd() && this.progressBar.update({
|
|
948
|
+
current: percentage,
|
|
949
|
+
message: `${msg} ${args.join(' ')}`
|
|
950
|
+
});
|
|
951
|
+
}), key = "progressBar", value = new ProgressBar(), key in this ? Object.defineProperty(this, key, {
|
|
952
|
+
value: value,
|
|
953
|
+
enumerable: !0,
|
|
954
|
+
configurable: !0,
|
|
955
|
+
writable: !0
|
|
956
|
+
}) : this[key] = value;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function webpack_define_property(obj, key, value) {
|
|
960
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
961
|
+
value: value,
|
|
962
|
+
enumerable: !0,
|
|
963
|
+
configurable: !0,
|
|
964
|
+
writable: !0
|
|
965
|
+
}) : obj[key] = value, obj;
|
|
966
|
+
}
|
|
967
|
+
let webpack_PLUGIN_NAME = 'ProgressPlugin';
|
|
968
|
+
class ProgressWebpackPlugin extends webpack.ProgressPlugin {
|
|
969
|
+
apply(compiler) {
|
|
970
|
+
super.apply(compiler), compiler.hooks.watchRun.tap(webpack_PLUGIN_NAME, ()=>{
|
|
971
|
+
(!utils_isDevServer() || global.__unpack_dev_server_started) && printDevLog(compiler, compiler.options.context);
|
|
972
|
+
}), compiler.hooks.afterDone.tap(webpack_PLUGIN_NAME, async (stats)=>{
|
|
973
|
+
this.isCompleted = !0, await compileDone(compiler, stats);
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
constructor(){
|
|
977
|
+
super({
|
|
978
|
+
entries: !1,
|
|
979
|
+
dependencies: !1,
|
|
980
|
+
activeModules: !0,
|
|
981
|
+
handler: isProd() ? (percentage, msg, ...args)=>{
|
|
982
|
+
this.isCompleted || this.progressBar.update({
|
|
983
|
+
current: percentage,
|
|
984
|
+
message: `${msg} ${args.join(' ').replace(/(\d+) active /, '')}`
|
|
985
|
+
});
|
|
986
|
+
} : void 0
|
|
987
|
+
}), webpack_define_property(this, "progressBar", new ProgressBar()), webpack_define_property(this, "isCompleted", !1);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
let BundleAnalyzerPlugin = __webpack_require__("compiled/webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
991
|
+
async function getBundlerConfig(unpackConfig) {
|
|
992
|
+
var _unpackConfig_build, _unpackConfig_build1, _minifyOptions_oxc, _unpackConfig_build2, _unpackConfig_build3, _unpackConfig_build4, _unpackConfig_build5, _unpackConfig_build6, _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8, _unpackConfig_performance, _unpackConfig_performance1, _unpackConfig_build7, _unpackConfig_resolve, _unpackConfig_resolve1, _unpackConfig_dev, _unpackConfig_build8, _unpackConfig_experiments;
|
|
993
|
+
let define, isRspack = 'rspack' === unpackConfig.bundler, HtmlPlugin = isRspack ? rspack.HtmlRspackPlugin : html_webpack_plugin, IgnorePlugin = isRspack ? rspack.IgnorePlugin : webpack.IgnorePlugin, CopyPlugin = isRspack ? rspack.CopyRspackPlugin : copy_webpack_plugin, tsconfigPath = node_path.resolve(unpackConfig.root, 'tsconfig.json'), isTs = node_fs.existsSync(tsconfigPath), minifyOptions = isPlainObject(null == (_unpackConfig_build = unpackConfig.build) ? void 0 : _unpackConfig_build.minify) ? null == (_unpackConfig_build1 = unpackConfig.build) ? void 0 : _unpackConfig_build1.minify : {}, oxcMinifyCompress = isPlainObject(null == (_minifyOptions_oxc = minifyOptions.oxc) ? void 0 : _minifyOptions_oxc.compress) ? minifyOptions.oxc.compress : {}, wasmFilename = 'js/[hash].module.wasm', { publicVars, filePaths: envFilePaths } = function({ cwd = process.cwd(), mode = getNodeEnv(), prefixes = [
|
|
994
|
+
'PUBLIC_'
|
|
995
|
+
], processEnv = process.env } = {}) {
|
|
996
|
+
if ('local' === mode) throw Error(`${colors.yellow('local')} cannot be used as a value for env mode, because ${colors.yellow('.env.local')} represents a temporary local file. Please use another value.`);
|
|
997
|
+
let filePaths = [
|
|
998
|
+
'.env',
|
|
999
|
+
'.env.local',
|
|
1000
|
+
`.env.${mode}`,
|
|
1001
|
+
`.env.${mode}.local`
|
|
1002
|
+
].map((filename)=>join(cwd, filename)).filter(isFileSync), parsed = {};
|
|
1003
|
+
for (let envPath of filePaths)Object.assign(parsed, function(src) {
|
|
1004
|
+
let match, obj = {}, lines = src.toString();
|
|
1005
|
+
for(lines = lines.replace(/\r\n?/gm, '\n'); null != (match = DOTENV_LINE.exec(lines));){
|
|
1006
|
+
let key = match[1], value = match[2] || '', maybeQuote = (value = value.trim())[0];
|
|
1007
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/gm, '$2'), '"' === maybeQuote && (value = (value = value.replace(/\\n/g, '\n')).replace(/\\r/g, '\r')), obj[key] = value;
|
|
1008
|
+
}
|
|
1009
|
+
return obj;
|
|
1010
|
+
}(node_fs.readFileSync(envPath))), logger_logger.debug('loaded env file:', envPath);
|
|
1011
|
+
parsed.NODE_ENV && (processEnv.NODE_ENV = parsed.NODE_ENV), expand({
|
|
1012
|
+
parsed,
|
|
1013
|
+
processEnv
|
|
1014
|
+
});
|
|
1015
|
+
let publicVars = {}, rawPublicVars = {}, normalizedPrefixes = Array.isArray(prefixes) ? prefixes : [
|
|
1016
|
+
prefixes
|
|
1017
|
+
];
|
|
1018
|
+
for (let key of Object.keys(processEnv))if (normalizedPrefixes.some((prefix)=>key.startsWith(prefix))) {
|
|
1019
|
+
let val = processEnv[key];
|
|
1020
|
+
publicVars[`import.meta.env.${key}`] = JSON.stringify(val), publicVars[`process.env.${key}`] = JSON.stringify(val), rawPublicVars[key] = val;
|
|
1021
|
+
}
|
|
1022
|
+
publicVars['import.meta.env'] = JSON.stringify(rawPublicVars), publicVars['process.env'] = JSON.stringify(rawPublicVars);
|
|
1023
|
+
let cleaned = !1;
|
|
1024
|
+
return {
|
|
1025
|
+
parsed,
|
|
1026
|
+
cleanup: ()=>{
|
|
1027
|
+
if (!cleaned) {
|
|
1028
|
+
for (let key of Object.keys(parsed))'NODE_ENV' !== key && processEnv[key] === parsed[key] && delete processEnv[key];
|
|
1029
|
+
cleaned = !0;
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
filePaths,
|
|
1033
|
+
publicVars,
|
|
1034
|
+
rawPublicVars
|
|
1035
|
+
};
|
|
1036
|
+
}({
|
|
1037
|
+
prefixes: unpackConfig.envPrefix,
|
|
1038
|
+
cwd: unpackConfig.root
|
|
1039
|
+
}), config = {
|
|
1040
|
+
context: unpackConfig.root,
|
|
1041
|
+
mode: isDev() ? 'development' : 'production',
|
|
1042
|
+
entry: unpackConfig.mpa ? {} : {
|
|
1043
|
+
main: await getEntry(unpackConfig.root, unpackConfig.entry)
|
|
1044
|
+
},
|
|
1045
|
+
stats: 'errors-only',
|
|
1046
|
+
output: {
|
|
1047
|
+
clean: !0,
|
|
1048
|
+
path: node_path.resolve(unpackConfig.root, null == (_unpackConfig_build2 = unpackConfig.build) ? void 0 : _unpackConfig_build2.outDir),
|
|
1049
|
+
filename: getOutputFilename({
|
|
1050
|
+
type: 'js',
|
|
1051
|
+
hash: null == (_unpackConfig_build3 = unpackConfig.build) ? void 0 : _unpackConfig_build3.filenameHash
|
|
1052
|
+
}),
|
|
1053
|
+
chunkFilename: getOutputFilename({
|
|
1054
|
+
type: 'js',
|
|
1055
|
+
hash: null == (_unpackConfig_build4 = unpackConfig.build) ? void 0 : _unpackConfig_build4.filenameHash,
|
|
1056
|
+
async: !0
|
|
1057
|
+
}),
|
|
1058
|
+
crossOriginLoading: 'anonymous',
|
|
1059
|
+
pathinfo: !1,
|
|
1060
|
+
publicPath: null == (_unpackConfig_build5 = unpackConfig.build) ? void 0 : _unpackConfig_build5.publicPath,
|
|
1061
|
+
webassemblyModuleFilename: wasmFilename,
|
|
1062
|
+
assetModuleFilename: 'assets/[name].[contenthash:8][ext]'
|
|
1063
|
+
},
|
|
1064
|
+
infrastructureLogging: {
|
|
1065
|
+
level: 'error'
|
|
1066
|
+
},
|
|
1067
|
+
devtool: null == (_unpackConfig_build6 = unpackConfig.build) ? void 0 : _unpackConfig_build6.sourceMap,
|
|
1068
|
+
module: {
|
|
1069
|
+
rules: [
|
|
1070
|
+
{
|
|
1071
|
+
test: /\.(png|jpg|jpeg|gif)$/i,
|
|
1072
|
+
type: 'asset'
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
1076
|
+
type: 'asset'
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
test: /\.wasm$/,
|
|
1080
|
+
dependency: 'url',
|
|
1081
|
+
type: 'asset/resource',
|
|
1082
|
+
generator: {
|
|
1083
|
+
filename: wasmFilename
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
]
|
|
1087
|
+
},
|
|
1088
|
+
plugins: [
|
|
1089
|
+
(define = {
|
|
1090
|
+
'import.meta.env.MODE': JSON.stringify(getNodeEnv()),
|
|
1091
|
+
'import.meta.env.DEV': isDev(),
|
|
1092
|
+
'import.meta.env.PROD': isProd(),
|
|
1093
|
+
...publicVars,
|
|
1094
|
+
...unpackConfig.define
|
|
1095
|
+
}, isRspack ? new rspack.DefinePlugin(define) : new webpack.DefinePlugin(define)),
|
|
1096
|
+
!unpackConfig.mpa && new HtmlPlugin({
|
|
1097
|
+
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || (isRspack ? void 0 : ''),
|
|
1098
|
+
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? !!isRspack && void 0 : TEMPLATE_CONTENT),
|
|
1099
|
+
templateParameters: {
|
|
1100
|
+
mountId: null == (_unpackConfig_html3 = unpackConfig.html) ? void 0 : _unpackConfig_html3.mountId,
|
|
1101
|
+
title: isFunction(null == (_unpackConfig_html4 = unpackConfig.html) ? void 0 : _unpackConfig_html4.title) ? null == (_unpackConfig_html5 = unpackConfig.html) ? void 0 : _unpackConfig_html5.title({
|
|
1102
|
+
entryName: 'index'
|
|
1103
|
+
}) : (null == (_unpackConfig_html6 = unpackConfig.html) ? void 0 : _unpackConfig_html6.title) || '',
|
|
1104
|
+
headTag: (null == (_unpackConfig_html7 = unpackConfig.html) ? void 0 : _unpackConfig_html7.headTag) || '',
|
|
1105
|
+
...null == (_unpackConfig_html8 = unpackConfig.html) ? void 0 : _unpackConfig_html8.templateParameters
|
|
1106
|
+
},
|
|
1107
|
+
minify: !1,
|
|
1108
|
+
chunks: [
|
|
1109
|
+
'main'
|
|
1110
|
+
]
|
|
1111
|
+
}),
|
|
1112
|
+
(null == (_unpackConfig_performance = unpackConfig.performance) ? void 0 : _unpackConfig_performance.bundleAnalyze) && isProd() && new BundleAnalyzerPlugin({
|
|
1113
|
+
analyzerPort: 'auto'
|
|
1114
|
+
}),
|
|
1115
|
+
(null == (_unpackConfig_performance1 = unpackConfig.performance) ? void 0 : _unpackConfig_performance1.removeMomentLocale) && new IgnorePlugin({
|
|
1116
|
+
resourceRegExp: /^\.\/locale$/,
|
|
1117
|
+
contextRegExp: /moment$/
|
|
1118
|
+
}),
|
|
1119
|
+
(null == (_unpackConfig_build7 = unpackConfig.build) ? void 0 : _unpackConfig_build7.copy) && new CopyPlugin({
|
|
1120
|
+
patterns: unpackConfig.build.copy
|
|
1121
|
+
}),
|
|
1122
|
+
unpackConfig.typeCheck && isDev() && isTs && new TsCheckerRspackPlugin({
|
|
1123
|
+
typescript: {
|
|
1124
|
+
mode: 'readonly',
|
|
1125
|
+
memoryLimit: 8192,
|
|
1126
|
+
configFile: tsconfigPath,
|
|
1127
|
+
typescriptPath: require.resolve("typescript", {
|
|
1128
|
+
paths: [
|
|
1129
|
+
unpackConfig.root
|
|
1130
|
+
]
|
|
1131
|
+
})
|
|
1132
|
+
},
|
|
1133
|
+
issue: {
|
|
1134
|
+
exclude: [
|
|
1135
|
+
({ file = '' })=>NODE_MODULES_REGEX.test(file)
|
|
1136
|
+
]
|
|
1137
|
+
},
|
|
1138
|
+
logger: {
|
|
1139
|
+
log (message) {
|
|
1140
|
+
message.includes('Found') && console.log(message.split(' in ')[0]);
|
|
1141
|
+
},
|
|
1142
|
+
error (message) {
|
|
1143
|
+
message.includes('RpcExitError') || message.includes('out of memory') || console.log(message.replace(/ERROR/g, 'Type Error'));
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}),
|
|
1147
|
+
new (isRspack ? ProgressRspackPlugin : ProgressWebpackPlugin)(),
|
|
1148
|
+
unpackConfig.lint && new OxlintPlugin()
|
|
1149
|
+
].filter(Boolean),
|
|
1150
|
+
externals: unpackConfig.externals,
|
|
1151
|
+
resolve: {
|
|
1152
|
+
alias: {
|
|
1153
|
+
'@': node_path.resolve(unpackConfig.root, 'src'),
|
|
1154
|
+
...isTs ? (()=>{
|
|
1155
|
+
var _json5_parse_compilerOptions, _json5_parse;
|
|
1156
|
+
let paths = null == (_json5_parse = json5.parse(node_fs.readFileSync(tsconfigPath, 'utf-8'))) || null == (_json5_parse_compilerOptions = _json5_parse.compilerOptions) ? void 0 : _json5_parse_compilerOptions.paths;
|
|
1157
|
+
return paths ? Object.keys(paths).reduce((acc, key)=>(acc[key.replace(/\/\*$/, '')] = node_path.resolve(unpackConfig.root, paths[key][0].replace(/\/\*$/, '')), acc), {}) : {};
|
|
1158
|
+
})() : {},
|
|
1159
|
+
...null == (_unpackConfig_resolve = unpackConfig.resolve) ? void 0 : _unpackConfig_resolve.alias
|
|
1160
|
+
},
|
|
1161
|
+
extensionAlias: {
|
|
1162
|
+
'.js': [
|
|
1163
|
+
'.js',
|
|
1164
|
+
'.ts',
|
|
1165
|
+
'.tsx'
|
|
1166
|
+
],
|
|
1167
|
+
'.jsx': [
|
|
1168
|
+
'.jsx',
|
|
1169
|
+
'.tsx'
|
|
1170
|
+
]
|
|
1171
|
+
},
|
|
1172
|
+
extensions: [
|
|
1173
|
+
'.tsx',
|
|
1174
|
+
'.ts',
|
|
1175
|
+
'.jsx',
|
|
1176
|
+
'.js',
|
|
1177
|
+
'.wasm',
|
|
1178
|
+
'.json',
|
|
1179
|
+
...(null == (_unpackConfig_resolve1 = unpackConfig.resolve) ? void 0 : _unpackConfig_resolve1.extensions) || []
|
|
1180
|
+
]
|
|
1181
|
+
},
|
|
1182
|
+
experiments: {
|
|
1183
|
+
lazyCompilation: (null == (_unpackConfig_dev = unpackConfig.dev) ? void 0 : _unpackConfig_dev.lazyCompilation) && utils_isDevServer() && {
|
|
1184
|
+
imports: !0,
|
|
1185
|
+
entries: !!unpackConfig.mpa
|
|
1186
|
+
},
|
|
1187
|
+
css: !1,
|
|
1188
|
+
asyncWebAssembly: !0
|
|
1189
|
+
},
|
|
1190
|
+
optimization: {
|
|
1191
|
+
moduleIds: isDev() ? 'named' : 'deterministic',
|
|
1192
|
+
minimize: !!(null == (_unpackConfig_build8 = unpackConfig.build) ? void 0 : _unpackConfig_build8.minify),
|
|
1193
|
+
minimizer: [
|
|
1194
|
+
new JsMinifyPlugin({
|
|
1195
|
+
...minifyOptions.oxc,
|
|
1196
|
+
compress: {
|
|
1197
|
+
target: DEFAULT_ES_TARGET,
|
|
1198
|
+
...oxcMinifyCompress
|
|
1199
|
+
}
|
|
1200
|
+
}),
|
|
1201
|
+
new LightningcssMinifyPlugin({
|
|
1202
|
+
targets: DEFAULT_LIGHTNINGCSS_TARGET,
|
|
1203
|
+
...minifyOptions.lightningcss
|
|
1204
|
+
})
|
|
1205
|
+
]
|
|
1206
|
+
},
|
|
1207
|
+
watchOptions: {
|
|
1208
|
+
ignored: /[\\/](?:\.git|node_modules)[\\/]/
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
for (let plugin of (config = (({ config, unpackConfig })=>{
|
|
1212
|
+
let { chunkSplit } = unpackConfig.performance || {};
|
|
1213
|
+
if (null == chunkSplit ? void 0 : chunkSplit.strategy) {
|
|
1214
|
+
let forceSplittingGroups = {};
|
|
1215
|
+
(null == chunkSplit ? void 0 : chunkSplit.forceSplitting) && (forceSplittingGroups = function(forceSplitting, strategy) {
|
|
1216
|
+
let cacheGroups = {};
|
|
1217
|
+
for (let [key, regexp] of Array.isArray(forceSplitting) ? forceSplitting.map((regexp, index)=>[
|
|
1218
|
+
`force-split-${index}`,
|
|
1219
|
+
regexp
|
|
1220
|
+
]) : Object.entries(forceSplitting))cacheGroups[key] = {
|
|
1221
|
+
test: regexp,
|
|
1222
|
+
name: key,
|
|
1223
|
+
chunks: 'all',
|
|
1224
|
+
priority: +('single-vendor' === strategy),
|
|
1225
|
+
enforce: !0
|
|
1226
|
+
};
|
|
1227
|
+
return cacheGroups;
|
|
1228
|
+
}(chunkSplit.forceSplitting, chunkSplit.strategy)), setValueByPath(config, [
|
|
1229
|
+
'optimization',
|
|
1230
|
+
'splitChunks'
|
|
1231
|
+
], SPLIT_STRATEGY_DISPATCHER[chunkSplit.strategy]({
|
|
1232
|
+
defaultConfig: {
|
|
1233
|
+
chunks: 'all'
|
|
1234
|
+
},
|
|
1235
|
+
forceSplittingGroups,
|
|
1236
|
+
chunkSplit
|
|
1237
|
+
}));
|
|
1238
|
+
}
|
|
1239
|
+
return config;
|
|
1240
|
+
})({
|
|
1241
|
+
config: config = (null == (_unpackConfig_experiments = unpackConfig.experiments) ? void 0 : _unpackConfig_experiments.css) ? function({ config, unpackConfig }) {
|
|
1242
|
+
var _unpackConfig_build, _unpackConfig_build1, _unpackConfig_css, _unpackConfig_css1, _config_module_rules, _config_module, _config_module_rules1, _config_module1, _config_module_rules2, _config_module2;
|
|
1243
|
+
config.output.cssFilename = getOutputFilename({
|
|
1244
|
+
type: 'css',
|
|
1245
|
+
hash: null == (_unpackConfig_build = unpackConfig.build) ? void 0 : _unpackConfig_build.filenameHash
|
|
1246
|
+
}), config.output.cssChunkFilename = getOutputFilename({
|
|
1247
|
+
type: 'css',
|
|
1248
|
+
hash: null == (_unpackConfig_build1 = unpackConfig.build) ? void 0 : _unpackConfig_build1.filenameHash,
|
|
1249
|
+
async: !0
|
|
1250
|
+
}), setValueByPath(config, [
|
|
1251
|
+
'experiments',
|
|
1252
|
+
'css'
|
|
1253
|
+
], !0);
|
|
1254
|
+
let sourceMap = null == (_unpackConfig_css = unpackConfig.css) ? void 0 : _unpackConfig_css.sourceMap, modules = null == (_unpackConfig_css1 = unpackConfig.css) ? void 0 : _unpackConfig_css1.modules;
|
|
1255
|
+
isPlainObject(modules) || !1 === modules || (modules = {}), !1 !== modules && !1 !== modules.auto && (setValueByPath(config, [
|
|
1256
|
+
'module',
|
|
1257
|
+
'parser',
|
|
1258
|
+
'css/module'
|
|
1259
|
+
], {
|
|
1260
|
+
namedExports: CSS_NAMED_EXPORT
|
|
1261
|
+
}), setValueByPath(config, [
|
|
1262
|
+
'module',
|
|
1263
|
+
'generator',
|
|
1264
|
+
'css/module'
|
|
1265
|
+
], {
|
|
1266
|
+
localIdentName: modules.localIdentName || CSS_MODULES_LOCAL_IDENT_NAME,
|
|
1267
|
+
exportsConvention: EXPORT_LOCALS_CONVENTION
|
|
1268
|
+
}));
|
|
1269
|
+
let withCssModules = ({ use })=>{
|
|
1270
|
+
if (!1 === modules) return !1;
|
|
1271
|
+
let auto = modules.auto;
|
|
1272
|
+
return !1 !== auto && {
|
|
1273
|
+
test: (resourcePath)=>resourcePath.includes('node_modules') ? CSS_MODULES_REGEX.test(resourcePath) : isRegExp(auto) ? auto.test(resourcePath) : isFunction(auto) ? auto(resourcePath) : CSS_MODULES_REGEX.test(resourcePath),
|
|
1274
|
+
use,
|
|
1275
|
+
type: 'css/module'
|
|
1276
|
+
};
|
|
1277
|
+
}, getThreadLoader = ()=>{
|
|
1278
|
+
var _unpackConfig_build;
|
|
1279
|
+
return (null == (_unpackConfig_build = unpackConfig.build) ? void 0 : _unpackConfig_build.parallel) && isProd() && {
|
|
1280
|
+
loader: require.resolve('thread-loader'),
|
|
1281
|
+
options: THREAD_OPTIONS
|
|
1282
|
+
};
|
|
1283
|
+
}, getLessLoader = ()=>{
|
|
1284
|
+
var _unpackConfig_css;
|
|
1285
|
+
return {
|
|
1286
|
+
loader: getCompiledPkgPath('less-loader'),
|
|
1287
|
+
options: {
|
|
1288
|
+
lessOptions: mergeConfig({
|
|
1289
|
+
javascriptEnabled: !0
|
|
1290
|
+
}, (null == (_unpackConfig_css = unpackConfig.css) ? void 0 : _unpackConfig_css.less) || {}),
|
|
1291
|
+
implementation: getUserDepPath(unpackConfig.root, 'less'),
|
|
1292
|
+
sourceMap
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
};
|
|
1296
|
+
null == (_config_module = config.module) || null == (_config_module_rules = _config_module.rules) || _config_module_rules.push({
|
|
1297
|
+
test: /\.less$/i,
|
|
1298
|
+
oneOf: [
|
|
1299
|
+
withCssModules({
|
|
1300
|
+
use: [
|
|
1301
|
+
getThreadLoader(),
|
|
1302
|
+
getLessLoader()
|
|
1303
|
+
].filter(Boolean)
|
|
1304
|
+
}),
|
|
1305
|
+
{
|
|
1306
|
+
use: [
|
|
1307
|
+
getThreadLoader(),
|
|
1308
|
+
getLessLoader()
|
|
1309
|
+
].filter(Boolean),
|
|
1310
|
+
type: 'css'
|
|
1311
|
+
}
|
|
1312
|
+
].filter(Boolean)
|
|
1313
|
+
});
|
|
1314
|
+
let getCssLoader = ()=>{
|
|
1315
|
+
var _unpackConfig_css, _unpackConfig_css1, _unpackConfig_css2;
|
|
1316
|
+
return (null == (_unpackConfig_css = unpackConfig.css) ? void 0 : _unpackConfig_css.transformer) === 'lightningcss' ? {
|
|
1317
|
+
loader: node_path.resolve(experimentCss_dirname, './lightningcssLoader.mjs'),
|
|
1318
|
+
options: mergeConfig((null == (_unpackConfig_css1 = unpackConfig.css) ? void 0 : _unpackConfig_css1.lightningcss) || {}, {
|
|
1319
|
+
sourceMap,
|
|
1320
|
+
targets: DEFAULT_LIGHTNINGCSS_TARGET
|
|
1321
|
+
})
|
|
1322
|
+
} : {
|
|
1323
|
+
loader: getCompiledPkgPath('postcss-loader'),
|
|
1324
|
+
options: {
|
|
1325
|
+
postcssOptions: null == (_unpackConfig_css2 = unpackConfig.css) ? void 0 : _unpackConfig_css2.postcss,
|
|
1326
|
+
sourceMap
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
};
|
|
1330
|
+
null == (_config_module1 = config.module) || null == (_config_module_rules1 = _config_module1.rules) || _config_module_rules1.push({
|
|
1331
|
+
test: /\.css$/i,
|
|
1332
|
+
oneOf: [
|
|
1333
|
+
withCssModules({
|
|
1334
|
+
use: [
|
|
1335
|
+
getCssLoader()
|
|
1336
|
+
]
|
|
1337
|
+
}),
|
|
1338
|
+
{
|
|
1339
|
+
use: [
|
|
1340
|
+
getCssLoader()
|
|
1341
|
+
],
|
|
1342
|
+
type: 'css'
|
|
1343
|
+
}
|
|
1344
|
+
].filter(Boolean)
|
|
1345
|
+
});
|
|
1346
|
+
let getSassLoader = ()=>{
|
|
1347
|
+
var _unpackConfig_css;
|
|
1348
|
+
return {
|
|
1349
|
+
loader: getCompiledPkgPath('sass-loader'),
|
|
1350
|
+
options: {
|
|
1351
|
+
api: 'modern-compiler',
|
|
1352
|
+
implementation: getUserDepPath(unpackConfig.root, [
|
|
1353
|
+
'sass-embedded',
|
|
1354
|
+
'sass'
|
|
1355
|
+
]),
|
|
1356
|
+
sassOptions: null == (_unpackConfig_css = unpackConfig.css) ? void 0 : _unpackConfig_css.sass,
|
|
1357
|
+
sourceMap
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
};
|
|
1361
|
+
return null == (_config_module2 = config.module) || null == (_config_module_rules2 = _config_module2.rules) || _config_module_rules2.push({
|
|
1362
|
+
test: /\.s[ac]ss$/i,
|
|
1363
|
+
oneOf: [
|
|
1364
|
+
withCssModules({
|
|
1365
|
+
use: [
|
|
1366
|
+
getSassLoader()
|
|
1367
|
+
]
|
|
1368
|
+
}),
|
|
1369
|
+
{
|
|
1370
|
+
use: [
|
|
1371
|
+
getSassLoader()
|
|
1372
|
+
],
|
|
1373
|
+
type: 'css'
|
|
1374
|
+
}
|
|
1375
|
+
].filter(Boolean)
|
|
1376
|
+
}), isDev() && config.plugins.push(new TypedCssModulesPlugin({
|
|
1377
|
+
modules
|
|
1378
|
+
})), config;
|
|
1379
|
+
}({
|
|
1380
|
+
config,
|
|
1381
|
+
unpackConfig
|
|
1382
|
+
}) : function({ config, unpackConfig }) {
|
|
1383
|
+
var _unpackConfig_css, _unpackConfig_css1, _unpackConfig_build, _unpackConfig_css2, _config_module_rules, _config_module, _config_module_rules1, _config_module1, _unpackConfig_css3, _config_module_rules2, _config_module2, _unpackConfig_build1, _unpackConfig_build2, _unpackConfig_css4, _unpackConfig_css5, _unpackConfig_css6;
|
|
1384
|
+
let CssExtractPlugin = 'rspack' === unpackConfig.bundler ? rspack.CssExtractRspackPlugin : mini_css_extract_plugin, sourceMap = null == (_unpackConfig_css = unpackConfig.css) ? void 0 : _unpackConfig_css.sourceMap, modules = null == (_unpackConfig_css1 = unpackConfig.css) ? void 0 : _unpackConfig_css1.modules;
|
|
1385
|
+
isPlainObject(modules) || !1 === modules || (modules = {});
|
|
1386
|
+
let getCommonRules = ({ importLoaders })=>[
|
|
1387
|
+
utils_isDevServer() ? {
|
|
1388
|
+
loader: getCompiledPkgPath('style-loader')
|
|
1389
|
+
} : {
|
|
1390
|
+
loader: CssExtractPlugin.loader,
|
|
1391
|
+
options: {
|
|
1392
|
+
defaultExport: !0
|
|
1393
|
+
}
|
|
1394
|
+
},
|
|
1395
|
+
isDev() && {
|
|
1396
|
+
loader: node_path.resolve(css_dirname, './typedCssModulesLoader.mjs'),
|
|
1397
|
+
options: {
|
|
1398
|
+
modules
|
|
1399
|
+
}
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
loader: getCompiledPkgPath('css-loader'),
|
|
1403
|
+
options: {
|
|
1404
|
+
importLoaders,
|
|
1405
|
+
modules: {
|
|
1406
|
+
auto: (()=>{
|
|
1407
|
+
if (!1 === modules) return !1;
|
|
1408
|
+
let auto = modules.auto;
|
|
1409
|
+
return !1 !== auto && ((resourcePath)=>resourcePath.includes('node_modules') ? CSS_MODULES_REGEX.test(resourcePath) : isRegExp(auto) ? auto.test(resourcePath) : isFunction(auto) ? auto(resourcePath) : CSS_MODULES_REGEX.test(resourcePath));
|
|
1410
|
+
})(),
|
|
1411
|
+
localIdentName: !1 !== modules && (modules.localIdentName || CSS_MODULES_LOCAL_IDENT_NAME),
|
|
1412
|
+
exportLocalsConvention: EXPORT_LOCALS_CONVENTION,
|
|
1413
|
+
namedExport: CSS_NAMED_EXPORT
|
|
1414
|
+
},
|
|
1415
|
+
sourceMap
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
].filter(Boolean);
|
|
1419
|
+
return utils_isDevServer() || config.plugins.push(new CssExtractPlugin({
|
|
1420
|
+
filename: getOutputFilename({
|
|
1421
|
+
type: 'css',
|
|
1422
|
+
hash: null == (_unpackConfig_build1 = unpackConfig.build) ? void 0 : _unpackConfig_build1.filenameHash
|
|
1423
|
+
}),
|
|
1424
|
+
chunkFilename: getOutputFilename({
|
|
1425
|
+
type: 'css',
|
|
1426
|
+
hash: null == (_unpackConfig_build2 = unpackConfig.build) ? void 0 : _unpackConfig_build2.filenameHash,
|
|
1427
|
+
async: !0
|
|
1428
|
+
})
|
|
1429
|
+
})), null == (_config_module = config.module) || null == (_config_module_rules = _config_module.rules) || _config_module_rules.push({
|
|
1430
|
+
test: /\.less$/i,
|
|
1431
|
+
use: [
|
|
1432
|
+
...getCommonRules({
|
|
1433
|
+
importLoaders: 1
|
|
1434
|
+
}),
|
|
1435
|
+
(null == (_unpackConfig_build = unpackConfig.build) ? void 0 : _unpackConfig_build.parallel) && isProd() && {
|
|
1436
|
+
loader: require.resolve('thread-loader'),
|
|
1437
|
+
options: THREAD_OPTIONS
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
loader: getCompiledPkgPath('less-loader'),
|
|
1441
|
+
options: {
|
|
1442
|
+
lessOptions: mergeConfig({
|
|
1443
|
+
javascriptEnabled: !0
|
|
1444
|
+
}, (null == (_unpackConfig_css2 = unpackConfig.css) ? void 0 : _unpackConfig_css2.less) || {}),
|
|
1445
|
+
implementation: getUserDepPath(unpackConfig.root, 'less'),
|
|
1446
|
+
sourceMap
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
].filter(Boolean)
|
|
1450
|
+
}), null == (_config_module1 = config.module) || null == (_config_module_rules1 = _config_module1.rules) || _config_module_rules1.push({
|
|
1451
|
+
test: /\.css$/i,
|
|
1452
|
+
use: [
|
|
1453
|
+
...getCommonRules({
|
|
1454
|
+
importLoaders: 1
|
|
1455
|
+
}),
|
|
1456
|
+
(null == (_unpackConfig_css4 = unpackConfig.css) ? void 0 : _unpackConfig_css4.transformer) === 'lightningcss' ? {
|
|
1457
|
+
loader: node_path.resolve(css_dirname, './lightningcssLoader.mjs'),
|
|
1458
|
+
options: mergeConfig((null == (_unpackConfig_css5 = unpackConfig.css) ? void 0 : _unpackConfig_css5.lightningcss) || {}, {
|
|
1459
|
+
sourceMap,
|
|
1460
|
+
targets: DEFAULT_LIGHTNINGCSS_TARGET
|
|
1461
|
+
})
|
|
1462
|
+
} : {
|
|
1463
|
+
loader: getCompiledPkgPath('postcss-loader'),
|
|
1464
|
+
options: {
|
|
1465
|
+
postcssOptions: null == (_unpackConfig_css6 = unpackConfig.css) ? void 0 : _unpackConfig_css6.postcss,
|
|
1466
|
+
sourceMap
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
]
|
|
1470
|
+
}), null == (_config_module2 = config.module) || null == (_config_module_rules2 = _config_module2.rules) || _config_module_rules2.push({
|
|
1471
|
+
test: /\.s[ac]ss$/i,
|
|
1472
|
+
use: [
|
|
1473
|
+
...getCommonRules({
|
|
1474
|
+
importLoaders: 1
|
|
1475
|
+
}),
|
|
1476
|
+
{
|
|
1477
|
+
loader: getCompiledPkgPath('sass-loader'),
|
|
1478
|
+
options: {
|
|
1479
|
+
api: 'modern-compiler',
|
|
1480
|
+
implementation: getUserDepPath(unpackConfig.root, [
|
|
1481
|
+
'sass-embedded',
|
|
1482
|
+
'sass'
|
|
1483
|
+
]),
|
|
1484
|
+
sassOptions: null == (_unpackConfig_css3 = unpackConfig.css) ? void 0 : _unpackConfig_css3.sass,
|
|
1485
|
+
sourceMap
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
]
|
|
1489
|
+
}), config;
|
|
1490
|
+
}({
|
|
1491
|
+
config,
|
|
1492
|
+
unpackConfig
|
|
1493
|
+
}),
|
|
1494
|
+
unpackConfig
|
|
1495
|
+
}), config = await applyCacheConfig({
|
|
1496
|
+
config,
|
|
1497
|
+
unpackConfig,
|
|
1498
|
+
envFilePaths
|
|
1499
|
+
}), getNormalizedPluginsByHook('bundlerConfig', unpackConfig.plugins)))config = await plugin.bundlerConfig(config, {
|
|
1500
|
+
...unpackConfig._context,
|
|
1501
|
+
unpackConfig,
|
|
1502
|
+
mergeConfig: mergeConfig
|
|
1503
|
+
});
|
|
1504
|
+
return unpackConfig.bundlerConfig && (config = isFunction(unpackConfig.bundlerConfig) ? await unpackConfig.bundlerConfig(config, {
|
|
1505
|
+
mergeConfig: mergeConfig
|
|
1506
|
+
}) : mergeConfig(config, unpackConfig.bundlerConfig)), config;
|
|
1507
|
+
}
|
|
1508
|
+
async function unpackBuild(unpackConfig) {
|
|
1509
|
+
let compiler = ('rspack' === unpackConfig.bundler ? rspack : webpack)(await getBundlerConfig(unpackConfig)), handler = (err, stats)=>{
|
|
1510
|
+
if (err) {
|
|
1511
|
+
console.error(err.stack || err), err.details && console.error(err.details);
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
(null == stats ? void 0 : stats.hasErrors()) && console.log(stats.toString({
|
|
1515
|
+
colors: !0,
|
|
1516
|
+
preset: 'errors-only'
|
|
1517
|
+
})), isWatch() || compiler.close(()=>{});
|
|
1518
|
+
};
|
|
1519
|
+
isWatch() ? compiler.watch({}, handler) : compiler.run(handler);
|
|
1520
|
+
}
|
|
1521
|
+
let restartCleaners = [];
|
|
1522
|
+
var openBrowser_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
1523
|
+
async function openBrowser(url) {
|
|
1524
|
+
if ('darwin' === process.platform) try {
|
|
1525
|
+
let ps = await execAsync('ps cax'), openedBrowser = [
|
|
1526
|
+
'Google Chrome Canary',
|
|
1527
|
+
'Google Chrome Dev',
|
|
1528
|
+
'Google Chrome Beta',
|
|
1529
|
+
'Google Chrome',
|
|
1530
|
+
'Microsoft Edge',
|
|
1531
|
+
'Brave Browser',
|
|
1532
|
+
'Vivaldi',
|
|
1533
|
+
'Chromium'
|
|
1534
|
+
].find((b)=>ps.includes(b));
|
|
1535
|
+
if (openedBrowser) return await execAsync(`osascript openChrome.applescript "${encodeURI(url)}" "${openedBrowser}"`, {
|
|
1536
|
+
cwd: node_path.join(openBrowser_dirname, '../bin')
|
|
1537
|
+
}), !0;
|
|
1538
|
+
} catch (err) {
|
|
1539
|
+
logger_logger.error(err);
|
|
1540
|
+
}
|
|
1541
|
+
try {
|
|
1542
|
+
return open_0(url).catch(()=>{}), !0;
|
|
1543
|
+
} catch (err) {
|
|
1544
|
+
return logger_logger.error(err), !1;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
function execAsync(command, options) {
|
|
1548
|
+
return new Promise((resolve, reject)=>{
|
|
1549
|
+
exec(command, options, (error, stdout)=>{
|
|
1550
|
+
error ? reject(error) : resolve(stdout.toString());
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
let getExternalLibraryName = (pkgName)=>({
|
|
1555
|
+
react: 'React',
|
|
1556
|
+
'react-dom': 'ReactDOM',
|
|
1557
|
+
'react-router-dom': 'ReactRouterDOM'
|
|
1558
|
+
})[pkgName] || pkgName, getExternalValue = (pkgName)=>`window ${getExternalLibraryName(pkgName)}`, prebundleDeps = async ({ unpackConfig })=>{
|
|
1559
|
+
var _unpackConfig_dev;
|
|
1560
|
+
let count = {
|
|
1561
|
+
total: 0,
|
|
1562
|
+
bundled: 0
|
|
1563
|
+
}, failedDeps = [], root = unpackConfig.root, failedDepsCachePath = node_path.resolve(root, TEMP_DIR, 'failed-deps.json'), failedCache = node_fs.existsSync(failedDepsCachePath) ? JSON.parse(node_fs.readFileSync(failedDepsCachePath, 'utf-8')) : {}, updateProgress = ()=>{
|
|
1564
|
+
logUpdate(`${colors.magenta("\xbb")} optimizing dependencies (${count.bundled}/${count.total})`), count.total === count.bundled + failedDeps.length && console.log();
|
|
1565
|
+
}, userOptions = isPlainObject(null == (_unpackConfig_dev = unpackConfig.dev) ? void 0 : _unpackConfig_dev.prebundle) ? unpackConfig.dev.prebundle : {}, ignoreCSSDeps = userOptions.ignoreCSS || [], packageJson = JSON.parse(node_fs.readFileSync(node_path.resolve(root, 'package.json'), 'utf-8')), excludeDeps = [
|
|
1566
|
+
...((externals)=>{
|
|
1567
|
+
let existExternals = new Set();
|
|
1568
|
+
return Array.isArray(externals) ? externals.forEach((item)=>{
|
|
1569
|
+
isPlainObject(item) && Object.keys(item).forEach((key)=>existExternals.add(key));
|
|
1570
|
+
}) : isPlainObject(externals) && Object.keys(externals).forEach((key)=>existExternals.add(key)), Array.from(existExternals);
|
|
1571
|
+
})(unpackConfig.externals) || [],
|
|
1572
|
+
...userOptions.exclude || []
|
|
1573
|
+
], shouldIncludeDeps = Object.keys(packageJson.dependencies).filter((pkgName)=>!excludeDeps.includes(pkgName)), noEntryDeps = [], needBundleDeps = shouldIncludeDeps.map((pkgName)=>{
|
|
1574
|
+
let packageJson = JSON.parse(node_fs.readFileSync(node_path.resolve(root, 'node_modules', pkgName, 'package.json'), 'utf-8')), version = packageJson.version;
|
|
1575
|
+
if (failedCache[pkgName] === version) return;
|
|
1576
|
+
let entry = ((packageJson)=>{
|
|
1577
|
+
if (packageJson.module) return packageJson.module;
|
|
1578
|
+
if (packageJson.exports) {
|
|
1579
|
+
if (isString(packageJson.exports)) return packageJson.exports;
|
|
1580
|
+
let defaultExport = packageJson.exports['.'];
|
|
1581
|
+
if (defaultExport) {
|
|
1582
|
+
if (isString(defaultExport)) return defaultExport;
|
|
1583
|
+
if (isString(defaultExport.import)) return defaultExport.import;
|
|
1584
|
+
if (isString(defaultExport.browser)) return defaultExport.browser;
|
|
1585
|
+
if (isString(defaultExport.default)) return defaultExport.default;
|
|
1586
|
+
}
|
|
1587
|
+
if (isString(packageJson.exports.default)) return packageJson.exports.default;
|
|
1588
|
+
}
|
|
1589
|
+
if (packageJson.main) return packageJson.main;
|
|
1590
|
+
})(packageJson);
|
|
1591
|
+
if (!entry) {
|
|
1592
|
+
noEntryDeps.push(pkgName), failedCache[pkgName] = version;
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
return {
|
|
1596
|
+
name: pkgName,
|
|
1597
|
+
entry: node_path.resolve(root, 'node_modules', pkgName, entry),
|
|
1598
|
+
version
|
|
1599
|
+
};
|
|
1600
|
+
}).filter(Boolean), bundledDeps = await Promise.all(needBundleDeps.map((depInfo)=>(({ name, entry, version })=>new Promise((resolve)=>{
|
|
1601
|
+
let pkgDir = node_path.resolve(root, TEMP_DIR, 'umd', name), outDir = node_path.resolve(pkgDir, version), getResult = ()=>({
|
|
1602
|
+
name,
|
|
1603
|
+
assets: globSync('**/index.{js,css}', {
|
|
1604
|
+
cwd: outDir,
|
|
1605
|
+
absolute: !0
|
|
1606
|
+
})
|
|
1607
|
+
});
|
|
1608
|
+
if (node_fs.existsSync(outDir)) return void resolve(getResult());
|
|
1609
|
+
count.total++, updateProgress();
|
|
1610
|
+
let getSwcOptions = ({ tsx })=>({
|
|
1611
|
+
jsc: {
|
|
1612
|
+
parser: {
|
|
1613
|
+
tsx,
|
|
1614
|
+
syntax: "typescript",
|
|
1615
|
+
dynamicImport: !0,
|
|
1616
|
+
decorators: !0
|
|
1617
|
+
},
|
|
1618
|
+
transform: {
|
|
1619
|
+
react: {
|
|
1620
|
+
runtime: 'automatic'
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}), compiler = rspack({
|
|
1625
|
+
entry: {
|
|
1626
|
+
index: entry
|
|
1627
|
+
},
|
|
1628
|
+
context: root,
|
|
1629
|
+
mode: 'development',
|
|
1630
|
+
output: {
|
|
1631
|
+
clean: !0,
|
|
1632
|
+
path: outDir,
|
|
1633
|
+
pathinfo: !1,
|
|
1634
|
+
library: {
|
|
1635
|
+
name: getExternalLibraryName(name),
|
|
1636
|
+
type: 'umd',
|
|
1637
|
+
umdNamedDefine: !0
|
|
1638
|
+
},
|
|
1639
|
+
globalObject: 'this'
|
|
1640
|
+
},
|
|
1641
|
+
devtool: !1,
|
|
1642
|
+
module: {
|
|
1643
|
+
rules: [
|
|
1644
|
+
{
|
|
1645
|
+
test: /\.(j|t)s$/,
|
|
1646
|
+
use: [
|
|
1647
|
+
{
|
|
1648
|
+
loader: 'builtin:swc-loader',
|
|
1649
|
+
options: getSwcOptions({
|
|
1650
|
+
tsx: !1
|
|
1651
|
+
})
|
|
1652
|
+
}
|
|
1653
|
+
]
|
|
1654
|
+
},
|
|
1655
|
+
{
|
|
1656
|
+
test: /\.(j|t)sx$/,
|
|
1657
|
+
use: [
|
|
1658
|
+
{
|
|
1659
|
+
loader: 'builtin:swc-loader',
|
|
1660
|
+
options: getSwcOptions({
|
|
1661
|
+
tsx: !0
|
|
1662
|
+
})
|
|
1663
|
+
}
|
|
1664
|
+
]
|
|
1665
|
+
},
|
|
1666
|
+
{
|
|
1667
|
+
test: /\.less$/,
|
|
1668
|
+
type: 'css/auto',
|
|
1669
|
+
use: [
|
|
1670
|
+
{
|
|
1671
|
+
loader: getCompiledPkgPath('less-loader'),
|
|
1672
|
+
options: {
|
|
1673
|
+
lessOptions: {
|
|
1674
|
+
javascriptEnabled: !0
|
|
1675
|
+
},
|
|
1676
|
+
implementation: getUserDepPath(root, 'less')
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
]
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
test: /\.s[ac]ss$/i,
|
|
1683
|
+
type: 'css/auto',
|
|
1684
|
+
use: [
|
|
1685
|
+
{
|
|
1686
|
+
loader: getCompiledPkgPath('sass-loader'),
|
|
1687
|
+
options: {
|
|
1688
|
+
api: 'modern-compiler',
|
|
1689
|
+
implementation: getUserDepPath(root, [
|
|
1690
|
+
'sass-embedded',
|
|
1691
|
+
'sass'
|
|
1692
|
+
])
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
]
|
|
1696
|
+
}
|
|
1697
|
+
]
|
|
1698
|
+
},
|
|
1699
|
+
optimization: {
|
|
1700
|
+
splitChunks: !1
|
|
1701
|
+
},
|
|
1702
|
+
experiments: {
|
|
1703
|
+
css: !0
|
|
1704
|
+
},
|
|
1705
|
+
externals: {
|
|
1706
|
+
react: getExternalValue('react'),
|
|
1707
|
+
'react-dom': getExternalValue('react-dom'),
|
|
1708
|
+
'react-router-dom': getExternalValue('react-router-dom')
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
compiler.run((_, stats)=>{
|
|
1712
|
+
let isFailed = !1;
|
|
1713
|
+
(null == stats ? void 0 : stats.hasErrors()) ? (isFailed = !0, failedDeps.push(name), failedCache[name] = version, removeDir(outDir)) : count.bundled++, updateProgress(), compiler.close(()=>{
|
|
1714
|
+
resolve(isFailed ? void 0 : getResult());
|
|
1715
|
+
});
|
|
1716
|
+
});
|
|
1717
|
+
}))(depInfo))), cacheDir = node_path.dirname(failedDepsCachePath);
|
|
1718
|
+
node_fs.existsSync(cacheDir) || node_fs.mkdirSync(cacheDir, {
|
|
1719
|
+
recursive: !0
|
|
1720
|
+
}), node_fs.writeFileSync(failedDepsCachePath, JSON.stringify(failedCache, null, 2), 'utf-8'), failedDeps[0] && logger_logger.warn(`something went wrong while optimizing "${colors.bold(failedDeps.join(', '))}"`);
|
|
1721
|
+
let cachePath = node_path.resolve(root, TEMP_DIR, 'umd'), app = express();
|
|
1722
|
+
app.use(cors()), app.use("/umd", express.static(cachePath));
|
|
1723
|
+
let port = await getPort(), staticServer = app.listen(port, ()=>{});
|
|
1724
|
+
restartCleaners.push(()=>new Promise((resolve)=>staticServer.close(()=>resolve())));
|
|
1725
|
+
let externals = {}, jsAssets = [], cssAssets = [], preJsAssets = [];
|
|
1726
|
+
bundledDeps.filter(Boolean).forEach((dep)=>{
|
|
1727
|
+
dep && (externals[dep.name] = getExternalValue(dep.name), dep.assets.forEach((absPath)=>{
|
|
1728
|
+
let relativePath = node_path.relative(cachePath, absPath), preDeps = [
|
|
1729
|
+
'react',
|
|
1730
|
+
'react-dom',
|
|
1731
|
+
'react-router-dom'
|
|
1732
|
+
], serverPath = `//localhost:${port}/umd/${relativePath}`;
|
|
1733
|
+
switch(node_path.extname(relativePath)){
|
|
1734
|
+
case '.js':
|
|
1735
|
+
preDeps.includes(dep.name) ? preJsAssets.push({
|
|
1736
|
+
path: serverPath,
|
|
1737
|
+
order: preDeps.indexOf(dep.name)
|
|
1738
|
+
}) : jsAssets.push(serverPath);
|
|
1739
|
+
break;
|
|
1740
|
+
case '.css':
|
|
1741
|
+
ignoreCSSDeps.includes(dep.name) || cssAssets.push(serverPath);
|
|
1742
|
+
}
|
|
1743
|
+
}));
|
|
1744
|
+
}), unpackConfig.externals = Array.isArray(unpackConfig.externals) ? [
|
|
1745
|
+
externals,
|
|
1746
|
+
...unpackConfig.externals
|
|
1747
|
+
] : {
|
|
1748
|
+
...externals,
|
|
1749
|
+
...unpackConfig.externals
|
|
1750
|
+
};
|
|
1751
|
+
let HtmlPlugin = 'rspack' === unpackConfig.bundler ? rspack.HtmlRspackPlugin : html_webpack_plugin;
|
|
1752
|
+
return unpackConfig.plugins.push({
|
|
1753
|
+
name: 'unpack:prebundle',
|
|
1754
|
+
bundlerConfig: (config)=>{
|
|
1755
|
+
let PLUGIN_NAME = 'PluginInjectAssets';
|
|
1756
|
+
return config.plugins.push({
|
|
1757
|
+
apply: (compiler)=>{
|
|
1758
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
|
|
1759
|
+
HtmlPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapPromise(PLUGIN_NAME, async (args)=>{
|
|
1760
|
+
let sortedPreJsAssets = preJsAssets.sort((a, b)=>a.order - b.order).map((item)=>item.path);
|
|
1761
|
+
return args.assets.js.unshift(...sortedPreJsAssets, ...jsAssets), args.assets.css.unshift(...cssAssets), args;
|
|
1762
|
+
});
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
}), config;
|
|
1766
|
+
}
|
|
1767
|
+
}), unpackConfig;
|
|
1768
|
+
};
|
|
1769
|
+
async function unpackDev(originalUnpackConfig) {
|
|
1770
|
+
var _unpackConfig_dev, _unpackConfig_server, _unpackConfig_server1, _unpackConfig_dev1, _unpackConfig_server2;
|
|
1771
|
+
let unpackConfig = originalUnpackConfig, isRspack = 'rspack' === unpackConfig.bundler, bundler = isRspack ? rspack : webpack;
|
|
1772
|
+
(null == (_unpackConfig_dev = unpackConfig.dev) ? void 0 : _unpackConfig_dev.prebundle) && (unpackConfig = await prebundleDeps({
|
|
1773
|
+
unpackConfig
|
|
1774
|
+
}));
|
|
1775
|
+
let compiler = bundler(await getBundlerConfig(unpackConfig)), port = await getPort(null == (_unpackConfig_server = unpackConfig.server) ? void 0 : _unpackConfig_server.port), proxyConfig = null == (_unpackConfig_server1 = unpackConfig.server) ? void 0 : _unpackConfig_server1.proxy;
|
|
1776
|
+
isPlainObject(proxyConfig) && (proxyConfig = Object.entries(proxyConfig).map(([contextStr, target])=>({
|
|
1777
|
+
context: contextStr.split(','),
|
|
1778
|
+
target,
|
|
1779
|
+
changeOrigin: !0
|
|
1780
|
+
})));
|
|
1781
|
+
let devServerOptions = {
|
|
1782
|
+
hot: !0,
|
|
1783
|
+
port,
|
|
1784
|
+
open: !1,
|
|
1785
|
+
client: {
|
|
1786
|
+
overlay: !1
|
|
1787
|
+
},
|
|
1788
|
+
proxy: proxyConfig,
|
|
1789
|
+
devMiddleware: {
|
|
1790
|
+
writeToDisk: null == (_unpackConfig_dev1 = unpackConfig.dev) ? void 0 : _unpackConfig_dev1.writeToDisk
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
devServerOptions.setupMiddlewares = (middlewares)=>(middlewares.unshift((req, _, next)=>{
|
|
1794
|
+
var _req_headers_accept;
|
|
1795
|
+
(null == (_req_headers_accept = req.headers.accept) ? void 0 : _req_headers_accept.includes('html')) && (req.url = '/index.html'), next();
|
|
1796
|
+
}), isRspack && middlewares.unshift(experiments.lazyCompilationMiddleware(compiler)), middlewares);
|
|
1797
|
+
let server = new webpack_dev_server(devServerOptions, compiler);
|
|
1798
|
+
await server.start(), logger_logger.greet(` ${colors.green(`${colors.bold(unpackConfig._context.callerName.toUpperCase())} v2.4.2`)} ${colors.dim(`ready in ${colors.reset(Math.ceil(performance.now() - global.__unpack_start_time))}ms`)}\n`), getAddressUrls({
|
|
1799
|
+
port: port
|
|
1800
|
+
}).forEach((addr)=>{
|
|
1801
|
+
let url;
|
|
1802
|
+
console.log(` ${colors.green(colors.dim("\u279C"))} ${colors.dim(addr.label)}${(url = addr.url, colors.cyan(url.replace(/:(\d+)\//, (_, port)=>`:${colors.bold(port)}/`)))}`);
|
|
1803
|
+
}), logger_logger.wait('building...'), global.__unpack_dev_server_started = !0, restartCleaners.push(async ()=>await server.stop(), ()=>new Promise((resolve)=>compiler.close(()=>resolve())), ()=>{
|
|
1804
|
+
global.__unpack_dev_server_started = !1;
|
|
1805
|
+
});
|
|
1806
|
+
let open = null == (_unpackConfig_server2 = unpackConfig.server) ? void 0 : _unpackConfig_server2.open;
|
|
1807
|
+
if (open) {
|
|
1808
|
+
let url = isString(open) ? open : `http://localhost:${port}`;
|
|
1809
|
+
await openBrowser(url);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
function createUnpack({ cwd = process.cwd(), config, callerName = 'unpack' }) {
|
|
1813
|
+
let resolveConfig = async ()=>{
|
|
1814
|
+
let defaultConfig = {
|
|
1815
|
+
bundler: 'rspack',
|
|
1816
|
+
root: cwd,
|
|
1817
|
+
build: {
|
|
1818
|
+
outDir: 'dist',
|
|
1819
|
+
minify: isProd(),
|
|
1820
|
+
sourceMap: !isProd() && 'cheap-module-source-map',
|
|
1821
|
+
parallel: !0,
|
|
1822
|
+
filenameHash: !0
|
|
1823
|
+
},
|
|
1824
|
+
dev: {
|
|
1825
|
+
lazyCompilation: !0
|
|
1826
|
+
},
|
|
1827
|
+
server: {
|
|
1828
|
+
port: 3000
|
|
1829
|
+
},
|
|
1830
|
+
html: {
|
|
1831
|
+
mountId: 'root'
|
|
1832
|
+
},
|
|
1833
|
+
css: {
|
|
1834
|
+
modules: !0,
|
|
1835
|
+
transformer: 'postcss',
|
|
1836
|
+
sourceMap: !1
|
|
1837
|
+
},
|
|
1838
|
+
performance: {
|
|
1839
|
+
chunkSplit: {
|
|
1840
|
+
strategy: 'split-by-experience'
|
|
1841
|
+
}
|
|
1842
|
+
},
|
|
1843
|
+
typeCheck: !0,
|
|
1844
|
+
envPrefix: [
|
|
1845
|
+
'PUBLIC_'
|
|
1846
|
+
]
|
|
1847
|
+
}, _context = {
|
|
1848
|
+
callerName,
|
|
1849
|
+
version: "2.4.2"
|
|
1850
|
+
}, { plugins, bundlerConfig, ...rest } = mergeConfig(defaultConfig, config);
|
|
1851
|
+
for (let plugin of getNormalizedPluginsByHook('config', plugins))rest = await plugin.config(rest, {
|
|
1852
|
+
..._context,
|
|
1853
|
+
mergeConfig: mergeConfig
|
|
1854
|
+
});
|
|
1855
|
+
return {
|
|
1856
|
+
...rest,
|
|
1857
|
+
plugins,
|
|
1858
|
+
bundlerConfig,
|
|
1859
|
+
_context
|
|
1860
|
+
};
|
|
1861
|
+
};
|
|
1862
|
+
return {
|
|
1863
|
+
build: async ({ watch } = {})=>{
|
|
1864
|
+
setNodeEnv(watch ? 'development' : 'production'), console.log(colors.rainbow(`${callerName} v2.4.2`), colors.green(`building for ${watch ? 'development' : 'production'}...`)), unpackBuild(await resolveConfig());
|
|
1865
|
+
},
|
|
1866
|
+
dev: async ()=>{
|
|
1867
|
+
global.__unpack_start_time = performance.now(), setNodeEnv('development'), setDevServer(!0), unpackDev(await resolveConfig());
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
let GLOB_REGEX = /[*?{}[\]()!@+|]/;
|
|
1872
|
+
async function createChokidar(pathOrGlobs, root = process.cwd(), options) {
|
|
1873
|
+
let watchFiles = new Set(), globPatterns = pathOrGlobs.filter((pathOrGlob)=>!!GLOB_REGEX.test(pathOrGlob) || (watchFiles.add(pathOrGlob), !1));
|
|
1874
|
+
if (globPatterns.length) for (let file of (await glob(globPatterns, {
|
|
1875
|
+
cwd: root,
|
|
1876
|
+
absolute: !0
|
|
1877
|
+
})))watchFiles.add(file);
|
|
1878
|
+
return chokidar.watch(Array.from(watchFiles), {
|
|
1879
|
+
ignoreInitial: !0,
|
|
1880
|
+
ignorePermissionErrors: !0,
|
|
1881
|
+
...options
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
export { CSS_MODULES_LOCAL_IDENT_NAME, CSS_MODULES_REGEX, CSS_NAMED_EXPORT, DEFAULT_BROWSERSLIST, DEFAULT_DEV_HOST, DEFAULT_ES_TARGET, DEFAULT_LIGHTNINGCSS_TARGET, DEV_DEFAULT_FILENAME, EXPORT_LOCALS_CONVENTION, html_webpack_plugin as HtmlWebpackPlugin, logger_LogColor as LogColor, NODE_MODULES_REGEX, PROD_DEFAULT_FILENAME, TEMPLATE_CONTENT, TEMP_DIR, THREAD_OPTIONS, clearLine, colors, createChokidar, createUnpack, debounce, defineConfig, findExists, getAddressUrls, getCompiledPkgPath, getIpv4Interfaces, getNodeEnv, getPathInJs, getPort, getTime, getUserDepPath, getUserDepVersion, getValueByPath, isBoolean, isCI, isCSSModules, isDebug, isDev, utils_isDevServer as isDevServer, isEmptyDir, isFileExists, isFileSync, isFunction, isNodeVersionAtLeast, isObject, isPlainObject, isProd, isRegExp, isString, isUndefined, isWatch, isWin, loadConfig, logUpdate, logger_logger as logger, mergeConfig, pathExists, prettyTime, removeDir, resolveConfigPath, restartCleaners, rspack, setDevServer, setNodeEnv, setValueByPath, trackPerformance, webpack };
|