@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/index.d.ts
CHANGED
|
@@ -533,16 +533,24 @@ declare const zustandPlugin: (options?: ZustandPluginOptions | undefined) => Ywk
|
|
|
533
533
|
|
|
534
534
|
/**
|
|
535
535
|
* 启动开发服务器
|
|
536
|
+
*
|
|
537
|
+
* @param options.mode - env 文件模式,决定加载 .env.{mode},默认 "development"
|
|
538
|
+
* 例如 --mode staging 会加载 .env.staging,但 NODE_ENV 仍为 "development"
|
|
536
539
|
*/
|
|
537
540
|
declare function dev(options?: {
|
|
538
541
|
cwd?: string;
|
|
542
|
+
mode?: string;
|
|
539
543
|
}): Promise<void>;
|
|
540
544
|
|
|
541
545
|
/**
|
|
542
546
|
* 执行生产构建
|
|
547
|
+
*
|
|
548
|
+
* @param options.mode - env 文件模式,决定加载 .env.{mode},默认 "production"
|
|
549
|
+
* 例如 --mode staging 会加载 .env.staging,但 NODE_ENV 仍为 "production"
|
|
543
550
|
*/
|
|
544
551
|
declare function build(options?: {
|
|
545
552
|
cwd?: string;
|
|
553
|
+
mode?: string;
|
|
546
554
|
}): Promise<void>;
|
|
547
555
|
|
|
548
556
|
export { type AnalyticsPluginOptions, type GarfishPluginOptions, GeneratorContext, type I18nPluginOptions, type MockPluginOptions, PluginConfig, PluginHooks, type ReactQueryPluginOptions, type TailwindPluginOptions, type ThemePluginOptions, YwkfConfig, YwkfGenerator, YwkfGeneratorPlugin, type YwkfGeneratorPluginOptions, YwkfPlugin, type ZustandPluginOptions, analyticsPlugin, build, dev, garfishPlugin, i18nPlugin, mockPlugin, reactQueryPlugin, tailwindPlugin, themePlugin, zustandPlugin };
|
package/dist/index.js
CHANGED
|
@@ -4116,8 +4116,9 @@ import chalk2 from "chalk";
|
|
|
4116
4116
|
import { existsSync as existsSync11, readFileSync as readFileSync4 } from "fs";
|
|
4117
4117
|
import { resolve as resolve3 } from "path";
|
|
4118
4118
|
import dotenv from "dotenv";
|
|
4119
|
-
function preloadEnv(cwd, mode) {
|
|
4120
|
-
process.env.NODE_ENV =
|
|
4119
|
+
function preloadEnv(cwd, mode, nodeEnv) {
|
|
4120
|
+
process.env.NODE_ENV = nodeEnv;
|
|
4121
|
+
process.env.APP_MODE = mode;
|
|
4121
4122
|
const defaultPaths = [
|
|
4122
4123
|
resolve3(cwd, "config/env/.env.public"),
|
|
4123
4124
|
resolve3(cwd, ".env.public"),
|
|
@@ -4143,8 +4144,10 @@ function preloadEnv(cwd, mode) {
|
|
|
4143
4144
|
break;
|
|
4144
4145
|
}
|
|
4145
4146
|
}
|
|
4147
|
+
process.env.NODE_ENV = nodeEnv;
|
|
4148
|
+
process.env.APP_MODE = mode;
|
|
4146
4149
|
}
|
|
4147
|
-
function loadEnv(config, cwd, mode) {
|
|
4150
|
+
function loadEnv(config, cwd, mode, nodeEnv) {
|
|
4148
4151
|
const { env } = config;
|
|
4149
4152
|
const publicEnvPath = resolve3(cwd, env.publicEnvFile ?? "config/env/.env.public");
|
|
4150
4153
|
if (existsSync11(publicEnvPath)) {
|
|
@@ -4158,7 +4161,8 @@ function loadEnv(config, cwd, mode) {
|
|
|
4158
4161
|
process.env[key] = parsed[key];
|
|
4159
4162
|
}
|
|
4160
4163
|
}
|
|
4161
|
-
process.env.NODE_ENV =
|
|
4164
|
+
process.env.NODE_ENV = nodeEnv;
|
|
4165
|
+
process.env.APP_MODE = mode;
|
|
4162
4166
|
process.env.APP_NAME = process.env.APP_NAME || config.appName;
|
|
4163
4167
|
process.env.APP_CNAME = process.env.APP_CNAME || config.appCName;
|
|
4164
4168
|
process.env.OUTPUT_PATH = process.env.OUTPUT_PATH || config.output.path;
|
|
@@ -4238,10 +4242,11 @@ function renderBar(percent) {
|
|
|
4238
4242
|
return bar;
|
|
4239
4243
|
}
|
|
4240
4244
|
var DevPrinter = class {
|
|
4241
|
-
constructor(host, port, pluginNames) {
|
|
4245
|
+
constructor(host, port, pluginNames, isBuild = false) {
|
|
4242
4246
|
this.host = host;
|
|
4243
4247
|
this.port = port;
|
|
4244
4248
|
this.pluginNames = pluginNames;
|
|
4249
|
+
this.isBuild = isBuild;
|
|
4245
4250
|
}
|
|
4246
4251
|
startTime = 0;
|
|
4247
4252
|
lastProgressLine = "";
|
|
@@ -4304,7 +4309,11 @@ var DevPrinter = class {
|
|
|
4304
4309
|
const label = chalk.green("ready");
|
|
4305
4310
|
console.log(` ${label} built in ${chalk.bold(`${elapsed} s`)}`);
|
|
4306
4311
|
console.log();
|
|
4307
|
-
this.
|
|
4312
|
+
if (this.isBuild) {
|
|
4313
|
+
this.printPluginList();
|
|
4314
|
+
} else {
|
|
4315
|
+
this.printServerInfo();
|
|
4316
|
+
}
|
|
4308
4317
|
}
|
|
4309
4318
|
/**
|
|
4310
4319
|
* 标记新一轮编译开始(HMR)
|
|
@@ -4314,16 +4323,9 @@ var DevPrinter = class {
|
|
|
4314
4323
|
this.lastProgressLine = "";
|
|
4315
4324
|
}
|
|
4316
4325
|
/**
|
|
4317
|
-
*
|
|
4326
|
+
* 仅打印插件列表(build 模式使用)
|
|
4318
4327
|
*/
|
|
4319
|
-
|
|
4320
|
-
const localUrl = `http://localhost:${this.port}/`;
|
|
4321
|
-
const networkUrl = getNetworkAddress(this.port);
|
|
4322
|
-
console.log(` ${chalk.bold(">")} Local: ${chalk.cyan(localUrl)}`);
|
|
4323
|
-
if (networkUrl) {
|
|
4324
|
-
console.log(` ${chalk.bold(">")} Network: ${chalk.cyan(networkUrl)}`);
|
|
4325
|
-
}
|
|
4326
|
-
console.log();
|
|
4328
|
+
printPluginList() {
|
|
4327
4329
|
if (this.pluginNames.length > 0) {
|
|
4328
4330
|
console.log(` ${chalk.bold(">")} Plugins:`);
|
|
4329
4331
|
for (const name of this.pluginNames) {
|
|
@@ -4332,6 +4334,19 @@ var DevPrinter = class {
|
|
|
4332
4334
|
}
|
|
4333
4335
|
console.log();
|
|
4334
4336
|
}
|
|
4337
|
+
}
|
|
4338
|
+
/**
|
|
4339
|
+
* 打印服务器信息面板(dev 模式使用)
|
|
4340
|
+
*/
|
|
4341
|
+
printServerInfo() {
|
|
4342
|
+
const localUrl = `http://localhost:${this.port}/`;
|
|
4343
|
+
const networkUrl = getNetworkAddress(this.port);
|
|
4344
|
+
console.log(` ${chalk.bold(">")} Local: ${chalk.cyan(localUrl)}`);
|
|
4345
|
+
if (networkUrl) {
|
|
4346
|
+
console.log(` ${chalk.bold(">")} Network: ${chalk.cyan(networkUrl)}`);
|
|
4347
|
+
}
|
|
4348
|
+
console.log();
|
|
4349
|
+
this.printPluginList();
|
|
4335
4350
|
console.log(
|
|
4336
4351
|
` ${chalk.bold(">")} press ${chalk.bold("h + enter")} to show shortcuts`
|
|
4337
4352
|
);
|
|
@@ -4392,10 +4407,11 @@ function registerShortcuts(printer, opts) {
|
|
|
4392
4407
|
// src/cli/dev.ts
|
|
4393
4408
|
async function dev(options = {}) {
|
|
4394
4409
|
const cwd = options.cwd || process.cwd();
|
|
4410
|
+
const mode = options.mode || "development";
|
|
4395
4411
|
try {
|
|
4396
|
-
preloadEnv(cwd, "development");
|
|
4412
|
+
preloadEnv(cwd, mode, "development");
|
|
4397
4413
|
const { config } = await resolveConfig(cwd);
|
|
4398
|
-
loadEnv(config, cwd, "development");
|
|
4414
|
+
loadEnv(config, cwd, mode, "development");
|
|
4399
4415
|
const pluginManager = new PluginManager(config, cwd, true);
|
|
4400
4416
|
if (config.plugins && config.plugins.length > 0) {
|
|
4401
4417
|
await pluginManager.loadPlugins(config.plugins);
|
|
@@ -4526,10 +4542,11 @@ function printBuildResult(stats) {
|
|
|
4526
4542
|
}
|
|
4527
4543
|
async function build(options = {}) {
|
|
4528
4544
|
const cwd = options.cwd || process.cwd();
|
|
4545
|
+
const mode = options.mode || "production";
|
|
4529
4546
|
try {
|
|
4530
|
-
preloadEnv(cwd, "production");
|
|
4547
|
+
preloadEnv(cwd, mode, "production");
|
|
4531
4548
|
const { config } = await resolveConfig(cwd);
|
|
4532
|
-
loadEnv(config, cwd, "production");
|
|
4549
|
+
loadEnv(config, cwd, mode, "production");
|
|
4533
4550
|
const pluginManager = new PluginManager(config, cwd, false);
|
|
4534
4551
|
if (config.plugins && config.plugins.length > 0) {
|
|
4535
4552
|
await pluginManager.loadPlugins(config.plugins);
|
|
@@ -4538,7 +4555,7 @@ async function build(options = {}) {
|
|
|
4538
4555
|
let rspackConfig = createRspackConfig(config, cwd, { isDev: false });
|
|
4539
4556
|
rspackConfig = await pluginManager.applyRspackConfigHooks(rspackConfig);
|
|
4540
4557
|
const pluginNames = pluginManager.getPluginNames();
|
|
4541
|
-
const printer = new DevPrinter("localhost", 0, pluginNames);
|
|
4558
|
+
const printer = new DevPrinter("localhost", 0, pluginNames, true);
|
|
4542
4559
|
printer.printBanner();
|
|
4543
4560
|
printer.printBuildStart();
|
|
4544
4561
|
printer.updateProgress(0, "preparing");
|