@4399ywkf/core 5.0.13 → 5.0.16
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/cli/index.js +41 -24
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +37 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1809,8 +1809,9 @@ function createRspackConfig(config, cwd, options = {}) {
|
|
|
1809
1809
|
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
1810
1810
|
import { resolve as resolve2 } from "path";
|
|
1811
1811
|
import dotenv from "dotenv";
|
|
1812
|
-
function preloadEnv(cwd, mode) {
|
|
1813
|
-
process.env.NODE_ENV =
|
|
1812
|
+
function preloadEnv(cwd, mode, nodeEnv) {
|
|
1813
|
+
process.env.NODE_ENV = nodeEnv;
|
|
1814
|
+
process.env.APP_MODE = mode;
|
|
1814
1815
|
const defaultPaths = [
|
|
1815
1816
|
resolve2(cwd, "config/env/.env.public"),
|
|
1816
1817
|
resolve2(cwd, ".env.public"),
|
|
@@ -1836,8 +1837,10 @@ function preloadEnv(cwd, mode) {
|
|
|
1836
1837
|
break;
|
|
1837
1838
|
}
|
|
1838
1839
|
}
|
|
1840
|
+
process.env.NODE_ENV = nodeEnv;
|
|
1841
|
+
process.env.APP_MODE = mode;
|
|
1839
1842
|
}
|
|
1840
|
-
function loadEnv(config, cwd, mode) {
|
|
1843
|
+
function loadEnv(config, cwd, mode, nodeEnv) {
|
|
1841
1844
|
const { env } = config;
|
|
1842
1845
|
const publicEnvPath = resolve2(cwd, env.publicEnvFile ?? "config/env/.env.public");
|
|
1843
1846
|
if (existsSync6(publicEnvPath)) {
|
|
@@ -1851,7 +1854,8 @@ function loadEnv(config, cwd, mode) {
|
|
|
1851
1854
|
process.env[key] = parsed[key];
|
|
1852
1855
|
}
|
|
1853
1856
|
}
|
|
1854
|
-
process.env.NODE_ENV =
|
|
1857
|
+
process.env.NODE_ENV = nodeEnv;
|
|
1858
|
+
process.env.APP_MODE = mode;
|
|
1855
1859
|
process.env.APP_NAME = process.env.APP_NAME || config.appName;
|
|
1856
1860
|
process.env.APP_CNAME = process.env.APP_CNAME || config.appCName;
|
|
1857
1861
|
process.env.OUTPUT_PATH = process.env.OUTPUT_PATH || config.output.path;
|
|
@@ -2176,10 +2180,11 @@ function renderBar(percent) {
|
|
|
2176
2180
|
return bar;
|
|
2177
2181
|
}
|
|
2178
2182
|
var DevPrinter = class {
|
|
2179
|
-
constructor(host, port, pluginNames) {
|
|
2183
|
+
constructor(host, port, pluginNames, isBuild = false) {
|
|
2180
2184
|
this.host = host;
|
|
2181
2185
|
this.port = port;
|
|
2182
2186
|
this.pluginNames = pluginNames;
|
|
2187
|
+
this.isBuild = isBuild;
|
|
2183
2188
|
}
|
|
2184
2189
|
startTime = 0;
|
|
2185
2190
|
lastProgressLine = "";
|
|
@@ -2242,7 +2247,11 @@ var DevPrinter = class {
|
|
|
2242
2247
|
const label = chalk.green("ready");
|
|
2243
2248
|
console.log(` ${label} built in ${chalk.bold(`${elapsed} s`)}`);
|
|
2244
2249
|
console.log();
|
|
2245
|
-
this.
|
|
2250
|
+
if (this.isBuild) {
|
|
2251
|
+
this.printPluginList();
|
|
2252
|
+
} else {
|
|
2253
|
+
this.printServerInfo();
|
|
2254
|
+
}
|
|
2246
2255
|
}
|
|
2247
2256
|
/**
|
|
2248
2257
|
* 标记新一轮编译开始(HMR)
|
|
@@ -2252,16 +2261,9 @@ var DevPrinter = class {
|
|
|
2252
2261
|
this.lastProgressLine = "";
|
|
2253
2262
|
}
|
|
2254
2263
|
/**
|
|
2255
|
-
*
|
|
2264
|
+
* 仅打印插件列表(build 模式使用)
|
|
2256
2265
|
*/
|
|
2257
|
-
|
|
2258
|
-
const localUrl = `http://localhost:${this.port}/`;
|
|
2259
|
-
const networkUrl = getNetworkAddress(this.port);
|
|
2260
|
-
console.log(` ${chalk.bold(">")} Local: ${chalk.cyan(localUrl)}`);
|
|
2261
|
-
if (networkUrl) {
|
|
2262
|
-
console.log(` ${chalk.bold(">")} Network: ${chalk.cyan(networkUrl)}`);
|
|
2263
|
-
}
|
|
2264
|
-
console.log();
|
|
2266
|
+
printPluginList() {
|
|
2265
2267
|
if (this.pluginNames.length > 0) {
|
|
2266
2268
|
console.log(` ${chalk.bold(">")} Plugins:`);
|
|
2267
2269
|
for (const name of this.pluginNames) {
|
|
@@ -2270,6 +2272,19 @@ var DevPrinter = class {
|
|
|
2270
2272
|
}
|
|
2271
2273
|
console.log();
|
|
2272
2274
|
}
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* 打印服务器信息面板(dev 模式使用)
|
|
2278
|
+
*/
|
|
2279
|
+
printServerInfo() {
|
|
2280
|
+
const localUrl = `http://localhost:${this.port}/`;
|
|
2281
|
+
const networkUrl = getNetworkAddress(this.port);
|
|
2282
|
+
console.log(` ${chalk.bold(">")} Local: ${chalk.cyan(localUrl)}`);
|
|
2283
|
+
if (networkUrl) {
|
|
2284
|
+
console.log(` ${chalk.bold(">")} Network: ${chalk.cyan(networkUrl)}`);
|
|
2285
|
+
}
|
|
2286
|
+
console.log();
|
|
2287
|
+
this.printPluginList();
|
|
2273
2288
|
console.log(
|
|
2274
2289
|
` ${chalk.bold(">")} press ${chalk.bold("h + enter")} to show shortcuts`
|
|
2275
2290
|
);
|
|
@@ -2330,10 +2345,11 @@ function registerShortcuts(printer, opts) {
|
|
|
2330
2345
|
// src/cli/dev.ts
|
|
2331
2346
|
async function dev(options = {}) {
|
|
2332
2347
|
const cwd = options.cwd || process.cwd();
|
|
2348
|
+
const mode = options.mode || "development";
|
|
2333
2349
|
try {
|
|
2334
|
-
preloadEnv(cwd, "development");
|
|
2350
|
+
preloadEnv(cwd, mode, "development");
|
|
2335
2351
|
const { config } = await resolveConfig(cwd);
|
|
2336
|
-
loadEnv(config, cwd, "development");
|
|
2352
|
+
loadEnv(config, cwd, mode, "development");
|
|
2337
2353
|
const pluginManager = new PluginManager(config, cwd, true);
|
|
2338
2354
|
if (config.plugins && config.plugins.length > 0) {
|
|
2339
2355
|
await pluginManager.loadPlugins(config.plugins);
|
|
@@ -2464,10 +2480,11 @@ function printBuildResult(stats) {
|
|
|
2464
2480
|
}
|
|
2465
2481
|
async function build(options = {}) {
|
|
2466
2482
|
const cwd = options.cwd || process.cwd();
|
|
2483
|
+
const mode = options.mode || "production";
|
|
2467
2484
|
try {
|
|
2468
|
-
preloadEnv(cwd, "production");
|
|
2485
|
+
preloadEnv(cwd, mode, "production");
|
|
2469
2486
|
const { config } = await resolveConfig(cwd);
|
|
2470
|
-
loadEnv(config, cwd, "production");
|
|
2487
|
+
loadEnv(config, cwd, mode, "production");
|
|
2471
2488
|
const pluginManager = new PluginManager(config, cwd, false);
|
|
2472
2489
|
if (config.plugins && config.plugins.length > 0) {
|
|
2473
2490
|
await pluginManager.loadPlugins(config.plugins);
|
|
@@ -2476,7 +2493,7 @@ async function build(options = {}) {
|
|
|
2476
2493
|
let rspackConfig = createRspackConfig(config, cwd, { isDev: false });
|
|
2477
2494
|
rspackConfig = await pluginManager.applyRspackConfigHooks(rspackConfig);
|
|
2478
2495
|
const pluginNames = pluginManager.getPluginNames();
|
|
2479
|
-
const printer = new DevPrinter("localhost", 0, pluginNames);
|
|
2496
|
+
const printer = new DevPrinter("localhost", 0, pluginNames, true);
|
|
2480
2497
|
printer.printBanner();
|
|
2481
2498
|
printer.printBuildStart();
|
|
2482
2499
|
printer.updateProgress(0, "preparing");
|
|
@@ -2538,20 +2555,20 @@ try {
|
|
|
2538
2555
|
}
|
|
2539
2556
|
var program = new Command();
|
|
2540
2557
|
program.name("ywkf").description("4399\u8FD0\u7EF4\u5F00\u53D1\u524D\u7AEF\u6846\u67B6 CLI").version(version);
|
|
2541
|
-
program.command("dev").description("\u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668").option("-p, --port <port>", "\u6307\u5B9A\u7AEF\u53E3\u53F7").option("-h, --host <host>", "\u6307\u5B9A\u4E3B\u673A").action(async (options) => {
|
|
2558
|
+
program.command("dev").description("\u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668").option("-p, --port <port>", "\u6307\u5B9A\u7AEF\u53E3\u53F7").option("-h, --host <host>", "\u6307\u5B9A\u4E3B\u673A").option("-m, --mode <mode>", "\u6307\u5B9A\u73AF\u5883\u6A21\u5F0F\uFF0C\u52A0\u8F7D\u5BF9\u5E94\u7684 .env.{mode} \u6587\u4EF6", "development").action(async (options) => {
|
|
2542
2559
|
if (options.port) {
|
|
2543
2560
|
process.env.APP_PORT = options.port;
|
|
2544
2561
|
}
|
|
2545
2562
|
if (options.host) {
|
|
2546
2563
|
process.env.APP_HOST = options.host;
|
|
2547
2564
|
}
|
|
2548
|
-
await dev({ cwd: process.cwd() });
|
|
2565
|
+
await dev({ cwd: process.cwd(), mode: options.mode });
|
|
2549
2566
|
});
|
|
2550
|
-
program.command("build").description("\u6784\u5EFA\u751F\u4EA7\u73AF\u5883").option("--analyze", "\u542F\u7528\u6784\u5EFA\u5206\u6790").action(async (options) => {
|
|
2567
|
+
program.command("build").description("\u6784\u5EFA\u751F\u4EA7\u73AF\u5883").option("-m, --mode <mode>", "\u6307\u5B9A\u73AF\u5883\u6A21\u5F0F\uFF0C\u52A0\u8F7D\u5BF9\u5E94\u7684 .env.{mode} \u6587\u4EF6", "production").option("--analyze", "\u542F\u7528\u6784\u5EFA\u5206\u6790").action(async (options) => {
|
|
2551
2568
|
if (options.analyze) {
|
|
2552
2569
|
process.env.RSDOCTOR = "true";
|
|
2553
2570
|
}
|
|
2554
|
-
await build({ cwd: process.cwd() });
|
|
2571
|
+
await build({ cwd: process.cwd(), mode: options.mode });
|
|
2555
2572
|
});
|
|
2556
2573
|
program.command("start").description("\u542F\u52A8\u751F\u4EA7\u670D\u52A1\u5668\uFF08\u9700\u8981\u5148\u6267\u884C build\uFF09").action(() => {
|
|
2557
2574
|
console.log(chalk4.yellow("\u26A0\uFE0F start \u547D\u4EE4\u6682\u672A\u5B9E\u73B0\uFF0C\u8BF7\u4F7F\u7528 nginx \u6216\u5176\u4ED6\u9759\u6001\u670D\u52A1\u5668"));
|