@rspack/cli 1.1.8 → 1.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{629.js → 574.js} +12 -53
- package/dist/{629.mjs → 574.mjs} +9 -50
- package/dist/index.js +83 -238
- package/dist/index.mjs +59 -174
- package/dist/utils/crossImport.d.ts +1 -6
- package/package.json +5 -8
package/dist/index.js
CHANGED
|
@@ -1,77 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
"./src/utils/crossImport.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
4
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
5
|
-
Z: function() {
|
|
6
|
-
return __WEBPACK_DEFAULT_EXPORT__;
|
|
7
|
-
},
|
|
8
|
-
y: function() {
|
|
9
|
-
return dynamicImport;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
/* ESM import */ var node_url__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:url");
|
|
13
|
-
/* ESM import */ var _isEsmFile__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/utils/isEsmFile.ts");
|
|
14
|
-
/**
|
|
15
|
-
* Dynamically import files. It will make sure it's not being compiled away by TS/Rslib.
|
|
16
|
-
*/ const dynamicImport = new Function("path", "return import(path)");
|
|
17
|
-
const crossImport = async (path, cwd = process.cwd())=>{
|
|
18
|
-
if ((0, _isEsmFile__WEBPACK_IMPORTED_MODULE_1__ /* ["default"] */ .Z)(path, cwd)) {
|
|
19
|
-
const url = (0, node_url__WEBPACK_IMPORTED_MODULE_0__.pathToFileURL)(path).href;
|
|
20
|
-
const { default: config } = await dynamicImport(url);
|
|
21
|
-
return config;
|
|
22
|
-
}
|
|
23
|
-
let result = require(path);
|
|
24
|
-
// compatible with export default config in common ts config
|
|
25
|
-
if (result && "object" == typeof result && "default" in result) result = result.default || {};
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
/* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = crossImport;
|
|
29
|
-
},
|
|
30
|
-
"./src/utils/isEsmFile.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
31
|
-
// EXPORTS
|
|
32
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
33
|
-
Z: ()=>/* binding */ isEsmFile
|
|
34
|
-
});
|
|
35
|
-
// EXTERNAL MODULE: external "node:path"
|
|
36
|
-
var external_node_path_ = __webpack_require__("node:path");
|
|
37
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
|
|
38
|
-
// EXTERNAL MODULE: external "node:fs"
|
|
39
|
-
var external_node_fs_ = __webpack_require__("node:fs");
|
|
40
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_);
|
|
41
|
-
const readPackageUp_readPackageUp = (cwd = process.cwd())=>{
|
|
42
|
-
let currentDir = external_node_path_default().resolve(cwd);
|
|
43
|
-
let packageJsonPath = external_node_path_default().join(currentDir, "package.json");
|
|
44
|
-
while(!external_node_fs_default().existsSync(packageJsonPath)){
|
|
45
|
-
const parentDir = external_node_path_default().dirname(currentDir);
|
|
46
|
-
if (parentDir === currentDir) return null;
|
|
47
|
-
currentDir = parentDir;
|
|
48
|
-
packageJsonPath = external_node_path_default().join(currentDir, "package.json");
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, "utf8"));
|
|
52
|
-
} catch (error) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
/* ESM default export */ const readPackageUp = readPackageUp_readPackageUp;
|
|
57
|
-
const isEsmFile_isEsmFile = (filePath, cwd = process.cwd())=>{
|
|
58
|
-
const ext = external_node_path_default().extname(filePath);
|
|
59
|
-
if (/\.(mjs|mts)$/.test(ext)) return true;
|
|
60
|
-
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
61
|
-
const packageJson = readPackageUp(cwd);
|
|
62
|
-
return (null == packageJson ? void 0 : packageJson.type) === "module";
|
|
63
|
-
};
|
|
64
|
-
/* ESM default export */ const isEsmFile = isEsmFile_isEsmFile;
|
|
65
|
-
},
|
|
66
|
-
"@discoveryjs/json-ext": function(module) {
|
|
67
|
-
module.exports = require("@discoveryjs/json-ext");
|
|
68
|
-
},
|
|
69
3
|
"@rspack/core": function(module) {
|
|
70
4
|
module.exports = require("@rspack/core");
|
|
71
5
|
},
|
|
72
|
-
"@rspack/dev-server": function(module) {
|
|
73
|
-
module.exports = require("@rspack/dev-server");
|
|
74
|
-
},
|
|
75
6
|
"node:fs": function(module) {
|
|
76
7
|
module.exports = require("node:fs");
|
|
77
8
|
},
|
|
@@ -84,31 +15,37 @@ var __webpack_modules__ = {
|
|
|
84
15
|
"node:url": function(module) {
|
|
85
16
|
module.exports = require("node:url");
|
|
86
17
|
},
|
|
18
|
+
"@discoveryjs/json-ext": function(module) {
|
|
19
|
+
module.exports = import("@discoveryjs/json-ext");
|
|
20
|
+
},
|
|
21
|
+
"@rspack/dev-server": function(module) {
|
|
22
|
+
module.exports = import("@rspack/dev-server");
|
|
23
|
+
},
|
|
24
|
+
"exit-hook": function(module) {
|
|
25
|
+
module.exports = import("exit-hook");
|
|
26
|
+
},
|
|
27
|
+
interpret: function(module) {
|
|
28
|
+
module.exports = import("interpret");
|
|
29
|
+
},
|
|
30
|
+
rechoir: function(module) {
|
|
31
|
+
module.exports = import("rechoir");
|
|
32
|
+
},
|
|
87
33
|
"webpack-bundle-analyzer": function(module) {
|
|
88
|
-
module.exports =
|
|
34
|
+
module.exports = import("webpack-bundle-analyzer");
|
|
89
35
|
}
|
|
90
36
|
};
|
|
91
|
-
/************************************************************************/ // The module cache
|
|
92
37
|
var __webpack_module_cache__ = {};
|
|
93
|
-
// The require function
|
|
94
38
|
function __webpack_require__(moduleId) {
|
|
95
|
-
// Check if module is in cache
|
|
96
39
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
97
40
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
98
|
-
// Create a new module (and put it into the cache)
|
|
99
41
|
var module = __webpack_module_cache__[moduleId] = {
|
|
100
42
|
exports: {}
|
|
101
43
|
};
|
|
102
|
-
// Execute the module function
|
|
103
44
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
104
|
-
// Return the exports of the module
|
|
105
45
|
return module.exports;
|
|
106
46
|
}
|
|
107
|
-
// expose the modules object (__webpack_modules__)
|
|
108
47
|
__webpack_require__.m = __webpack_modules__;
|
|
109
|
-
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
|
110
48
|
(()=>{
|
|
111
|
-
// getDefaultExport function for compatibility with non-ESM modules
|
|
112
49
|
__webpack_require__.n = function(module) {
|
|
113
50
|
var getter = module && module.__esModule ? function() {
|
|
114
51
|
return module['default'];
|
|
@@ -121,49 +58,6 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
121
58
|
return getter;
|
|
122
59
|
};
|
|
123
60
|
})();
|
|
124
|
-
// webpack/runtime/create_fake_namespace_object
|
|
125
|
-
(()=>{
|
|
126
|
-
var getProto = Object.getPrototypeOf ? function(obj) {
|
|
127
|
-
return Object.getPrototypeOf(obj);
|
|
128
|
-
} : function(obj) {
|
|
129
|
-
return obj.__proto__;
|
|
130
|
-
};
|
|
131
|
-
var leafPrototypes;
|
|
132
|
-
// create a fake namespace object
|
|
133
|
-
// mode & 1: value is a module id, require it
|
|
134
|
-
// mode & 2: merge all properties of value into the ns
|
|
135
|
-
// mode & 4: return value when already ns object
|
|
136
|
-
// mode & 16: return value when it's Promise-like
|
|
137
|
-
// mode & 8|1: behave like require
|
|
138
|
-
__webpack_require__.t = function(value, mode) {
|
|
139
|
-
if (1 & mode) value = this(value);
|
|
140
|
-
if (8 & mode) return value;
|
|
141
|
-
if ('object' == typeof value && value) {
|
|
142
|
-
if (4 & mode && value.__esModule) return value;
|
|
143
|
-
if (16 & mode && 'function' == typeof value.then) return value;
|
|
144
|
-
}
|
|
145
|
-
var ns = Object.create(null);
|
|
146
|
-
__webpack_require__.r(ns);
|
|
147
|
-
var def = {};
|
|
148
|
-
leafPrototypes = leafPrototypes || [
|
|
149
|
-
null,
|
|
150
|
-
getProto({}),
|
|
151
|
-
getProto([]),
|
|
152
|
-
getProto(getProto)
|
|
153
|
-
];
|
|
154
|
-
for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
|
|
155
|
-
def[key] = function() {
|
|
156
|
-
return value[key];
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
|
-
def['default'] = function() {
|
|
160
|
-
return value;
|
|
161
|
-
};
|
|
162
|
-
__webpack_require__.d(ns, def);
|
|
163
|
-
return ns;
|
|
164
|
-
};
|
|
165
|
-
})();
|
|
166
|
-
// webpack/runtime/define_property_getters
|
|
167
61
|
(()=>{
|
|
168
62
|
__webpack_require__.d = function(exports1, definition) {
|
|
169
63
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -172,11 +66,8 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
172
66
|
});
|
|
173
67
|
};
|
|
174
68
|
})();
|
|
175
|
-
// webpack/runtime/ensure_chunk
|
|
176
69
|
(()=>{
|
|
177
70
|
__webpack_require__.f = {};
|
|
178
|
-
// This file contains only the entry chunk.
|
|
179
|
-
// The chunk loading function for additional chunks
|
|
180
71
|
__webpack_require__.e = function(chunkId) {
|
|
181
72
|
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
182
73
|
__webpack_require__.f[key](chunkId, promises);
|
|
@@ -184,24 +75,17 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
184
75
|
}, []));
|
|
185
76
|
};
|
|
186
77
|
})();
|
|
187
|
-
// webpack/runtime/get javascript chunk filename
|
|
188
78
|
(()=>{
|
|
189
|
-
// This function allow to reference chunks
|
|
190
79
|
__webpack_require__.u = function(chunkId) {
|
|
191
|
-
// return url for filenames not based on template
|
|
192
|
-
// return url for filenames based on template
|
|
193
80
|
return "" + chunkId + ".js";
|
|
194
81
|
};
|
|
195
82
|
})();
|
|
196
|
-
// webpack/runtime/has_own_property
|
|
197
83
|
(()=>{
|
|
198
84
|
__webpack_require__.o = function(obj, prop) {
|
|
199
85
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
200
86
|
};
|
|
201
87
|
})();
|
|
202
|
-
// webpack/runtime/make_namespace_object
|
|
203
88
|
(()=>{
|
|
204
|
-
// define __esModule on exports
|
|
205
89
|
__webpack_require__.r = function(exports1) {
|
|
206
90
|
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
207
91
|
value: 'Module'
|
|
@@ -211,48 +95,36 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
211
95
|
});
|
|
212
96
|
};
|
|
213
97
|
})();
|
|
214
|
-
// webpack/runtime/require_chunk_loading
|
|
215
98
|
(()=>{
|
|
216
99
|
var installedChunks = {
|
|
217
100
|
980: 1
|
|
218
101
|
};
|
|
219
|
-
// object to store loaded chunks
|
|
220
|
-
// "1" means "loaded", otherwise not loaded yet
|
|
221
102
|
var installChunk = function(chunk) {
|
|
222
103
|
var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
|
|
223
104
|
for(var moduleId in moreModules)if (__webpack_require__.o(moreModules, moduleId)) __webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
224
105
|
if (runtime) runtime(__webpack_require__);
|
|
225
106
|
for(var i = 0; i < chunkIds.length; i++)installedChunks[chunkIds[i]] = 1;
|
|
226
107
|
};
|
|
227
|
-
// require() chunk loading for javascript
|
|
228
108
|
__webpack_require__.f.require = function(chunkId, promises) {
|
|
229
|
-
// "1" is the signal for "already loaded"
|
|
230
109
|
if (!installedChunks[chunkId]) installChunk(require("./" + __webpack_require__.u(chunkId)));
|
|
231
110
|
};
|
|
232
111
|
})();
|
|
233
|
-
|
|
234
|
-
// ESM COMPAT FLAG
|
|
112
|
+
var __webpack_exports__ = {};
|
|
235
113
|
__webpack_require__.r(__webpack_exports__);
|
|
236
|
-
// EXPORTS
|
|
237
114
|
__webpack_require__.d(__webpack_exports__, {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
115
|
+
RspackCLI: ()=>RspackCLI,
|
|
116
|
+
defineConfig: ()=>defineConfig,
|
|
117
|
+
definePlugin: ()=>definePlugin
|
|
241
118
|
});
|
|
242
|
-
// EXTERNAL MODULE: external "node:path"
|
|
243
119
|
var external_node_path_ = __webpack_require__("node:path");
|
|
244
120
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
|
|
245
121
|
const external_node_util_namespaceObject = require("node:util");
|
|
246
122
|
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
247
|
-
// EXTERNAL MODULE: external "@rspack/core"
|
|
248
123
|
var core_ = __webpack_require__("@rspack/core");
|
|
249
124
|
const external_colorette_namespaceObject = require("colorette");
|
|
250
|
-
const external_semver_namespaceObject = require("semver");
|
|
251
|
-
var external_semver_default = /*#__PURE__*/ __webpack_require__.n(external_semver_namespaceObject);
|
|
252
125
|
const external_yargs_namespaceObject = require("yargs");
|
|
253
126
|
var external_yargs_default = /*#__PURE__*/ __webpack_require__.n(external_yargs_namespaceObject);
|
|
254
127
|
const helpers_namespaceObject = require("yargs/helpers");
|
|
255
|
-
// EXTERNAL MODULE: external "node:fs"
|
|
256
128
|
var external_node_fs_ = __webpack_require__("node:fs");
|
|
257
129
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_);
|
|
258
130
|
const commonOptions = (yargs)=>yargs.options({
|
|
@@ -333,7 +205,6 @@ const previewOptions = (yargs)=>yargs.positional("dir", {
|
|
|
333
205
|
type: "boolean",
|
|
334
206
|
describe: "open browser"
|
|
335
207
|
},
|
|
336
|
-
// same as devServer.server
|
|
337
208
|
server: {
|
|
338
209
|
type: "string",
|
|
339
210
|
describe: "Configuration items for the server."
|
|
@@ -351,9 +222,7 @@ function normalizeEnv(argv) {
|
|
|
351
222
|
let prevRef = previous;
|
|
352
223
|
splitKeys.forEach((key, index)=>{
|
|
353
224
|
let someKey = key;
|
|
354
|
-
// https://github.com/webpack/webpack-cli/issues/3284
|
|
355
225
|
if (someKey.endsWith("=")) {
|
|
356
|
-
// remove '=' from key
|
|
357
226
|
someKey = someKey.slice(0, -1);
|
|
358
227
|
prevRef[someKey] = void 0;
|
|
359
228
|
return;
|
|
@@ -370,27 +239,16 @@ function normalizeEnv(argv) {
|
|
|
370
239
|
const envObj = (argv.env ?? []).reduce(parseValue, {});
|
|
371
240
|
argv.env = envObj;
|
|
372
241
|
}
|
|
373
|
-
|
|
374
|
-
* set builtin env from cli - like `WEBPACK_BUNDLE=true`. also for `RSPACK_` prefixed.
|
|
375
|
-
* @param env the `argv.env` object
|
|
376
|
-
* @param envNameSuffix the added env will be `WEBPACK_${envNameSuffix}` and `RSPACK_${envNameSuffix}`
|
|
377
|
-
* @param value
|
|
378
|
-
*/ function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
242
|
+
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
379
243
|
const envNames = [
|
|
380
|
-
// TODO: breaking change
|
|
381
|
-
// `WEBPACK_${envNameSuffix}`,
|
|
382
244
|
`RSPACK_${envNameSuffix}`
|
|
383
245
|
];
|
|
384
246
|
for (const envName of envNames){
|
|
385
247
|
if (!(envName in env)) env[envName] = value;
|
|
386
248
|
}
|
|
387
249
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
* @returns the reference of `argv.env` object
|
|
391
|
-
*/ function ensureEnvObject(options) {
|
|
392
|
-
if (Array.isArray(options.env)) // in case that cli haven't got `normalizeEnv` middleware applied
|
|
393
|
-
normalizeEnv(options);
|
|
250
|
+
function ensureEnvObject(options) {
|
|
251
|
+
if (Array.isArray(options.env)) normalizeEnv(options);
|
|
394
252
|
options.env = options.env || {};
|
|
395
253
|
return options.env;
|
|
396
254
|
}
|
|
@@ -425,7 +283,7 @@ class BuildCommand {
|
|
|
425
283
|
const logger = cli.getLogger();
|
|
426
284
|
let createJsonStringifyStream;
|
|
427
285
|
if (options.json) {
|
|
428
|
-
const jsonExt = await Promise.resolve().then(__webpack_require__.
|
|
286
|
+
const jsonExt = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@discoveryjs/json-ext"));
|
|
429
287
|
createJsonStringifyStream = jsonExt.default.stringifyStream;
|
|
430
288
|
}
|
|
431
289
|
const errorHandler = (error, stats)=>{
|
|
@@ -444,13 +302,11 @@ class BuildCommand {
|
|
|
444
302
|
process.exit(2);
|
|
445
303
|
};
|
|
446
304
|
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
447
|
-
else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError)
|
|
448
|
-
.on("close", ()=>{
|
|
305
|
+
else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
|
|
449
306
|
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
450
307
|
});
|
|
451
308
|
} else {
|
|
452
309
|
const printedStats = stats.toString(statsOptions);
|
|
453
|
-
// Avoid extra empty line when `stats: 'none'`
|
|
454
310
|
if (printedStats) logger.raw(printedStats);
|
|
455
311
|
}
|
|
456
312
|
};
|
|
@@ -463,8 +319,6 @@ class BuildCommand {
|
|
|
463
319
|
const compiler = await cli.createCompiler(rspackOptions, "build", errorHandler);
|
|
464
320
|
if (!compiler || cli.isWatch(compiler)) return;
|
|
465
321
|
compiler.run((error, stats)=>{
|
|
466
|
-
// If there is a compilation error, the close method should not be called,
|
|
467
|
-
// Otherwise Rspack may generate invalid caches.
|
|
468
322
|
if (error || (null == stats ? void 0 : stats.hasErrors())) errorHandler(error, stats);
|
|
469
323
|
else compiler.close((closeErr)=>{
|
|
470
324
|
if (closeErr) logger.error(closeErr);
|
|
@@ -482,7 +336,6 @@ class PreviewCommand {
|
|
|
482
336
|
"preview",
|
|
483
337
|
"p"
|
|
484
338
|
], "run the rspack server for build output", previewOptions, async (options)=>{
|
|
485
|
-
// config、configName are necessary for loadConfig
|
|
486
339
|
const rspackOptions = {
|
|
487
340
|
config: options.config,
|
|
488
341
|
configName: options.configName,
|
|
@@ -490,13 +343,12 @@ class PreviewCommand {
|
|
|
490
343
|
...options
|
|
491
344
|
}
|
|
492
345
|
};
|
|
493
|
-
const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.
|
|
346
|
+
const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
|
|
494
347
|
let config = await cli.loadConfig(rspackOptions);
|
|
495
348
|
config = await getPreviewConfig(config, options);
|
|
496
349
|
if (!Array.isArray(config)) config = [
|
|
497
350
|
config
|
|
498
351
|
];
|
|
499
|
-
// find the possible devServer config
|
|
500
352
|
config = config.find((item)=>item.devServer) || config[0];
|
|
501
353
|
const devServerOptions = config.devServer;
|
|
502
354
|
try {
|
|
@@ -514,11 +366,9 @@ class PreviewCommand {
|
|
|
514
366
|
});
|
|
515
367
|
}
|
|
516
368
|
}
|
|
517
|
-
// get the devServerOptions from the config
|
|
518
369
|
async function getPreviewConfig(item, options) {
|
|
519
370
|
const internalPreviewConfig = async (item)=>{
|
|
520
371
|
var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
|
|
521
|
-
// all of the options that a preview static server needs(maybe not all)
|
|
522
372
|
item.devServer = {
|
|
523
373
|
static: {
|
|
524
374
|
directory: options.dir ? external_node_path_default().join(item.context ?? process.cwd(), options.dir) : (null === (_item_output = item.output) || void 0 === _item_output ? void 0 : _item_output.path) ?? external_node_path_default().join(item.context ?? process.cwd(), defaultRoot),
|
|
@@ -569,15 +419,7 @@ class ServeCommand {
|
|
|
569
419
|
...options
|
|
570
420
|
}
|
|
571
421
|
};
|
|
572
|
-
|
|
573
|
-
* webpack-dev-server will set `process.env.WEBPACK_SERVE` to true
|
|
574
|
-
* when its module is imported, so we have to lazy load the package
|
|
575
|
-
* to make sure the envvar is not set on build mode.
|
|
576
|
-
* when run in serve mode, we have to load the package before config
|
|
577
|
-
* module is imported so that the envvar `process.env.WEBPACK_SERVE`
|
|
578
|
-
* got in config module could be `true`.
|
|
579
|
-
* related issue: https://github.com/web-infra-dev/rspack/issues/6359
|
|
580
|
-
*/ const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "@rspack/dev-server", 23));
|
|
422
|
+
const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
|
|
581
423
|
const compiler = await cli.createCompiler(rspackOptions, "serve");
|
|
582
424
|
if (!compiler) return;
|
|
583
425
|
const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
|
|
@@ -586,16 +428,8 @@ class ServeCommand {
|
|
|
586
428
|
const possibleCompilers = compilers.filter((compiler)=>compiler.options.devServer);
|
|
587
429
|
const usedPorts = [];
|
|
588
430
|
const servers = [];
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
* however according to it's doc https://webpack.js.org/configuration/dev-server/#devserverhot
|
|
592
|
-
* It should use only the first one
|
|
593
|
-
*
|
|
594
|
-
* Choose the one for configure devServer
|
|
595
|
-
*/ const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
|
|
596
|
-
/**
|
|
597
|
-
* Rspack relies on devServer.hot to enable HMR
|
|
598
|
-
*/ for (const compiler of compilers){
|
|
431
|
+
const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
|
|
432
|
+
for (const compiler of compilers){
|
|
599
433
|
const devServer = compiler.options.devServer ??= {};
|
|
600
434
|
devServer.hot = options.hot ?? devServer.hot ?? true;
|
|
601
435
|
if (false !== devServer.client) {
|
|
@@ -610,9 +444,7 @@ class ServeCommand {
|
|
|
610
444
|
}
|
|
611
445
|
}
|
|
612
446
|
const result = compilerForDevServer.options.devServer ??= {};
|
|
613
|
-
|
|
614
|
-
* Enable this to tell Rspack that we need to enable React Refresh by default
|
|
615
|
-
*/ result.hot = options.hot ?? result.hot ?? true;
|
|
447
|
+
result.hot = options.hot ?? result.hot ?? true;
|
|
616
448
|
result.host = options.host || result.host;
|
|
617
449
|
result.port = options.port || result.port;
|
|
618
450
|
if (false !== result.client) {
|
|
@@ -645,12 +477,41 @@ class ServeCommand {
|
|
|
645
477
|
});
|
|
646
478
|
}
|
|
647
479
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
480
|
+
var external_node_url_ = __webpack_require__("node:url");
|
|
481
|
+
const readPackageUp = (cwd = process.cwd())=>{
|
|
482
|
+
let currentDir = external_node_path_default().resolve(cwd);
|
|
483
|
+
let packageJsonPath = external_node_path_default().join(currentDir, "package.json");
|
|
484
|
+
while(!external_node_fs_default().existsSync(packageJsonPath)){
|
|
485
|
+
const parentDir = external_node_path_default().dirname(currentDir);
|
|
486
|
+
if (parentDir === currentDir) return null;
|
|
487
|
+
currentDir = parentDir;
|
|
488
|
+
packageJsonPath = external_node_path_default().join(currentDir, "package.json");
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, "utf8"));
|
|
492
|
+
} catch (error) {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
const utils_readPackageUp = readPackageUp;
|
|
497
|
+
const isEsmFile = (filePath, cwd = process.cwd())=>{
|
|
498
|
+
const ext = external_node_path_default().extname(filePath);
|
|
499
|
+
if (/\.(mjs|mts)$/.test(ext)) return true;
|
|
500
|
+
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
501
|
+
const packageJson = utils_readPackageUp(cwd);
|
|
502
|
+
return (null == packageJson ? void 0 : packageJson.type) === "module";
|
|
503
|
+
};
|
|
504
|
+
const utils_isEsmFile = isEsmFile;
|
|
505
|
+
const crossImport = async (path, cwd = process.cwd())=>{
|
|
506
|
+
if (utils_isEsmFile(path, cwd)) {
|
|
507
|
+
const url = (0, external_node_url_.pathToFileURL)(path).href;
|
|
508
|
+
const { default: config } = await import(url);
|
|
509
|
+
return config;
|
|
510
|
+
}
|
|
511
|
+
let result = require(path);
|
|
512
|
+
if (result && "object" == typeof result && "default" in result) result = result.default || {};
|
|
513
|
+
return result;
|
|
514
|
+
};
|
|
654
515
|
const DEFAULT_EXTENSIONS = [
|
|
655
516
|
".js",
|
|
656
517
|
".ts",
|
|
@@ -659,28 +520,23 @@ const DEFAULT_EXTENSIONS = [
|
|
|
659
520
|
".cjs",
|
|
660
521
|
".cts"
|
|
661
522
|
];
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
*/ const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
|
|
666
|
-
/* ESM default export */ const utils_findConfig = findConfig;
|
|
667
|
-
// EXTERNAL MODULE: ./src/utils/isEsmFile.ts + 1 modules
|
|
668
|
-
var isEsmFile = __webpack_require__("./src/utils/isEsmFile.ts");
|
|
669
|
-
const isTsFile = (configPath)=>{
|
|
523
|
+
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
|
|
524
|
+
const utils_findConfig = findConfig;
|
|
525
|
+
const isTsFile_isTsFile = (configPath)=>{
|
|
670
526
|
const ext = external_node_path_default().extname(configPath);
|
|
671
527
|
return /\.(c|m)?ts$/.test(ext);
|
|
672
528
|
};
|
|
673
|
-
|
|
529
|
+
const isTsFile = isTsFile_isTsFile;
|
|
674
530
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
675
|
-
const registerLoader = (configPath)=>{
|
|
531
|
+
const registerLoader = async (configPath)=>{
|
|
676
532
|
const ext = external_node_path_default().extname(configPath);
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const extensions = Object.fromEntries(Object.entries(external_interpret_default().extensions).filter(([key])=>key === ext));
|
|
533
|
+
if (utils_isEsmFile(configPath) && isTsFile(configPath)) return;
|
|
534
|
+
const { default: interpret } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "interpret"));
|
|
535
|
+
const extensions = Object.fromEntries(Object.entries(interpret.extensions).filter(([key])=>key === ext));
|
|
681
536
|
if (0 === Object.keys(extensions).length) throw new Error(`config file "${configPath}" is not supported.`);
|
|
682
537
|
try {
|
|
683
|
-
|
|
538
|
+
const { default: rechoir } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "rechoir"));
|
|
539
|
+
rechoir.prepare(extensions, configPath);
|
|
684
540
|
} catch (error) {
|
|
685
541
|
const failures = null == error ? void 0 : error.failures;
|
|
686
542
|
if (failures) {
|
|
@@ -694,13 +550,13 @@ async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
|
694
550
|
if (options.config) {
|
|
695
551
|
const configPath = external_node_path_default().resolve(cwd, options.config);
|
|
696
552
|
if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
697
|
-
|
|
698
|
-
return
|
|
553
|
+
if (isTsFile(configPath)) await registerLoader(configPath);
|
|
554
|
+
return crossImport(configPath, cwd);
|
|
699
555
|
}
|
|
700
556
|
const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
701
557
|
if (defaultConfig) {
|
|
702
|
-
|
|
703
|
-
return
|
|
558
|
+
if (isTsFile(defaultConfig)) await registerLoader(defaultConfig);
|
|
559
|
+
return crossImport(defaultConfig, cwd);
|
|
704
560
|
}
|
|
705
561
|
return {};
|
|
706
562
|
}
|
|
@@ -730,8 +586,6 @@ class RspackCLI {
|
|
|
730
586
|
try {
|
|
731
587
|
compiler = (0, core_.rspack)(config, isWatch ? callback : void 0);
|
|
732
588
|
} catch (e) {
|
|
733
|
-
// Aligned with webpack-cli
|
|
734
|
-
// See: https://github.com/webpack/webpack-cli/blob/eea6adf7d34dfbfd3b5b784ece4a4664834f5a6a/packages/webpack-cli/src/webpack-cli.ts#L2394
|
|
735
589
|
if (e instanceof core_.ValidationError) {
|
|
736
590
|
this.getLogger().error(e.message);
|
|
737
591
|
process.exit(2);
|
|
@@ -764,7 +618,6 @@ class RspackCLI {
|
|
|
764
618
|
};
|
|
765
619
|
}
|
|
766
620
|
async run(argv) {
|
|
767
|
-
if (external_semver_default().lt(external_semver_default().clean(process.version), "14.0.0")) this.getLogger().warn(`Minimum recommended Node.js version is 14.0.0, current version is ${process.version}`);
|
|
768
621
|
this.program.showHelpOnFail(false);
|
|
769
622
|
this.program.usage("[options]");
|
|
770
623
|
this.program.scriptName("rspack");
|
|
@@ -787,13 +640,12 @@ class RspackCLI {
|
|
|
787
640
|
const commandDefaultEnv = isBuild ? "production" : "development";
|
|
788
641
|
const internalBuildConfig = async (item)=>{
|
|
789
642
|
if (options.entry) item.entry = {
|
|
790
|
-
main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
|
|
643
|
+
main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
|
|
791
644
|
};
|
|
792
|
-
// to set output.path
|
|
793
645
|
item.output = item.output || {};
|
|
794
646
|
if (options["output-path"]) item.output.path = external_node_path_default().resolve(process.cwd(), options["output-path"]);
|
|
795
647
|
if (options.analyze) {
|
|
796
|
-
const { BundleAnalyzerPlugin } = await Promise.resolve().then(__webpack_require__.
|
|
648
|
+
const { BundleAnalyzerPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "webpack-bundle-analyzer"));
|
|
797
649
|
(item.plugins ??= []).push({
|
|
798
650
|
name: "rspack-bundle-analyzer",
|
|
799
651
|
apply (compiler) {
|
|
@@ -805,16 +657,12 @@ class RspackCLI {
|
|
|
805
657
|
}
|
|
806
658
|
if (options.profile) item.profile = true;
|
|
807
659
|
if (process.env.RSPACK_PROFILE) {
|
|
808
|
-
const { applyProfile } = await __webpack_require__.e(
|
|
660
|
+
const { applyProfile } = await __webpack_require__.e("574").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
809
661
|
await applyProfile(process.env.RSPACK_PROFILE, item);
|
|
810
662
|
}
|
|
811
|
-
// cli --watch overrides the watch config
|
|
812
663
|
if (options.watch) item.watch = options.watch;
|
|
813
|
-
// auto set default mode if user config don't set it
|
|
814
664
|
if (!item.mode) item.mode = commandDefaultEnv ?? "none";
|
|
815
|
-
// user parameters always has highest priority than default mode and config mode
|
|
816
665
|
if (options.mode) item.mode = options.mode;
|
|
817
|
-
// false is also a valid value for sourcemap, so don't override it
|
|
818
666
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
819
667
|
if (isServe) {
|
|
820
668
|
const installed = (item.plugins ||= []).find((item)=>item instanceof core_.ProgressPlugin);
|
|
@@ -843,7 +691,6 @@ class RspackCLI {
|
|
|
843
691
|
if ("function" == typeof loadedConfig) {
|
|
844
692
|
var _options_argv;
|
|
845
693
|
loadedConfig = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
|
|
846
|
-
// if return promise we should await its result
|
|
847
694
|
if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
|
|
848
695
|
}
|
|
849
696
|
if (options.configName) {
|
|
@@ -852,8 +699,6 @@ class RspackCLI {
|
|
|
852
699
|
let found;
|
|
853
700
|
found = Array.isArray(loadedConfig) ? loadedConfig.find((options)=>options.name === configName) : loadedConfig.name === configName ? loadedConfig : void 0;
|
|
854
701
|
if (!found) notFoundConfigNames.push(configName);
|
|
855
|
-
// WARNING: if config is not found, the program will exit
|
|
856
|
-
// so assert here is okay to avoid runtime filtering
|
|
857
702
|
return found;
|
|
858
703
|
});
|
|
859
704
|
if (notFoundConfigNames.length > 0) {
|
|
@@ -883,7 +728,7 @@ function definePlugin(plugin) {
|
|
|
883
728
|
return plugin;
|
|
884
729
|
}
|
|
885
730
|
var __webpack_export_target__ = exports;
|
|
886
|
-
for(var
|
|
731
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
887
732
|
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
888
733
|
value: true
|
|
889
734
|
});
|