weapp-vite 1.4.4 → 1.5.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/{chunk-XX7JRD75.mjs → chunk-SKX4EDQU.mjs} +31 -18
- package/dist/cli.cjs +157 -33
- package/dist/cli.mjs +118 -5
- package/dist/{config-D8l0cMnj.d.cts → config-wDAzBoFy.d.cts} +18 -0
- package/dist/{config-D8l0cMnj.d.ts → config-wDAzBoFy.d.ts} +18 -0
- package/dist/config.d.cts +2 -1
- package/dist/config.d.ts +2 -1
- package/dist/index.cjs +41 -28
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +1 -1
- package/package.json +6 -4
|
@@ -3,7 +3,7 @@ import logger from "@weapp-core/logger";
|
|
|
3
3
|
var logger_default = logger;
|
|
4
4
|
|
|
5
5
|
// package.json
|
|
6
|
-
var version = "1.
|
|
6
|
+
var version = "1.5.0";
|
|
7
7
|
|
|
8
8
|
// src/constants.ts
|
|
9
9
|
var VERSION = version;
|
|
@@ -13,11 +13,10 @@ var supportedCssLangs = ["wxss", "scss", "less", "sass", "styl"];
|
|
|
13
13
|
// src/context.ts
|
|
14
14
|
import { createRequire } from "node:module";
|
|
15
15
|
import process from "node:process";
|
|
16
|
-
import { addExtension
|
|
16
|
+
import { addExtension, defu, isObject as isObject2, objectHash, removeExtension } from "@weapp-core/shared";
|
|
17
17
|
import { watch } from "chokidar";
|
|
18
18
|
import fs6 from "fs-extra";
|
|
19
19
|
import path5 from "pathe";
|
|
20
|
-
import { build as tsupBuild } from "tsup";
|
|
21
20
|
import { build, loadConfigFromFile } from "vite";
|
|
22
21
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
23
22
|
|
|
@@ -167,6 +166,9 @@ function resolveJson(entry, aliasEntries) {
|
|
|
167
166
|
}
|
|
168
167
|
}
|
|
169
168
|
}
|
|
169
|
+
if (Reflect.has(json, "$schema")) {
|
|
170
|
+
delete json.$schema;
|
|
171
|
+
}
|
|
170
172
|
return stringifyJson(json);
|
|
171
173
|
}
|
|
172
174
|
}
|
|
@@ -174,14 +176,14 @@ function resolveJson(entry, aliasEntries) {
|
|
|
174
176
|
// src/utils/projectConfig.ts
|
|
175
177
|
import fs3 from "fs-extra";
|
|
176
178
|
import path3 from "pathe";
|
|
177
|
-
function getProjectConfig(root, options) {
|
|
179
|
+
async function getProjectConfig(root, options) {
|
|
178
180
|
const baseJsonPath = path3.resolve(root, "project.config.json");
|
|
179
181
|
const privateJsonPath = path3.resolve(root, "project.private.config.json");
|
|
180
182
|
let baseJson = {};
|
|
181
183
|
let privateJson = {};
|
|
182
|
-
if (fs3.
|
|
184
|
+
if (await fs3.exists(baseJsonPath)) {
|
|
183
185
|
try {
|
|
184
|
-
baseJson = fs3.
|
|
186
|
+
baseJson = await fs3.readJson(baseJsonPath) || {};
|
|
185
187
|
} catch {
|
|
186
188
|
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
|
|
187
189
|
}
|
|
@@ -189,9 +191,9 @@ function getProjectConfig(root, options) {
|
|
|
189
191
|
throw new Error(`\u5728 ${root} \u76EE\u5F55\u4E0B\u627E\u4E0D\u5230 project.config.json`);
|
|
190
192
|
}
|
|
191
193
|
if (!options?.ignorePrivate) {
|
|
192
|
-
if (fs3.
|
|
194
|
+
if (await fs3.exists(privateJsonPath)) {
|
|
193
195
|
try {
|
|
194
|
-
privateJson = fs3.
|
|
196
|
+
privateJson = await fs3.readJson(privateJsonPath) || {};
|
|
195
197
|
} catch {
|
|
196
198
|
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.private.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
|
|
197
199
|
}
|
|
@@ -201,7 +203,6 @@ function getProjectConfig(root, options) {
|
|
|
201
203
|
}
|
|
202
204
|
|
|
203
205
|
// src/utils/scan.ts
|
|
204
|
-
import { addExtension, removeExtension } from "@weapp-core/shared";
|
|
205
206
|
import fs4 from "fs-extra";
|
|
206
207
|
|
|
207
208
|
// src/plugins/parse.ts
|
|
@@ -325,10 +326,11 @@ function vitePluginWeapp(ctx, subPackageMeta) {
|
|
|
325
326
|
},
|
|
326
327
|
async load(id) {
|
|
327
328
|
if (entriesSet.has(id)) {
|
|
328
|
-
const
|
|
329
|
+
const code = await fs5.readFile(id, "utf8");
|
|
330
|
+
const ms = new MagicString(code);
|
|
329
331
|
for (const ext of supportedCssLangs) {
|
|
330
332
|
const mayBeCssPath = changeFileExtension(id, ext);
|
|
331
|
-
if (fs5.
|
|
333
|
+
if (await fs5.exists(mayBeCssPath)) {
|
|
332
334
|
this.addWatchFile(mayBeCssPath);
|
|
333
335
|
ms.prepend(`import '${mayBeCssPath}'
|
|
334
336
|
`);
|
|
@@ -466,7 +468,7 @@ var CompilerContext = class {
|
|
|
466
468
|
*
|
|
467
469
|
*/
|
|
468
470
|
get mpDistRoot() {
|
|
469
|
-
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot
|
|
471
|
+
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot;
|
|
470
472
|
}
|
|
471
473
|
async internalDev(inlineConfig) {
|
|
472
474
|
const watcher = await build(
|
|
@@ -572,8 +574,11 @@ var CompilerContext = class {
|
|
|
572
574
|
}
|
|
573
575
|
}
|
|
574
576
|
async loadDefaultConfig() {
|
|
575
|
-
const projectConfig = getProjectConfig(this.cwd);
|
|
577
|
+
const projectConfig = await getProjectConfig(this.cwd);
|
|
576
578
|
this.projectConfig = projectConfig;
|
|
579
|
+
if (!this.mpDistRoot) {
|
|
580
|
+
throw new Error("\u8BF7\u5728 `project.config.json` \u91CC\u8BBE\u7F6E `miniprogramRoot`, \u6BD4\u5982\u53EF\u4EE5\u8BBE\u7F6E\u4E3A `dist/` ");
|
|
581
|
+
}
|
|
577
582
|
const packageJsonPath = path5.resolve(this.cwd, "package.json");
|
|
578
583
|
const external = [];
|
|
579
584
|
if (await fs6.exists(packageJsonPath)) {
|
|
@@ -600,11 +605,11 @@ var CompilerContext = class {
|
|
|
600
605
|
entryFileNames: (chunkInfo) => {
|
|
601
606
|
const name = this.relativeSrcRoot(chunkInfo.name);
|
|
602
607
|
if (name.endsWith(".ts")) {
|
|
603
|
-
const baseFileName =
|
|
608
|
+
const baseFileName = removeExtension(name);
|
|
604
609
|
if (baseFileName.endsWith(".wxs")) {
|
|
605
610
|
return baseFileName;
|
|
606
611
|
}
|
|
607
|
-
return
|
|
612
|
+
return addExtension(baseFileName, ".js");
|
|
608
613
|
}
|
|
609
614
|
return name;
|
|
610
615
|
}
|
|
@@ -652,8 +657,8 @@ var CompilerContext = class {
|
|
|
652
657
|
// miniprogram
|
|
653
658
|
// https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
|
|
654
659
|
async buildNpm(options) {
|
|
660
|
+
const { build: tsupBuild } = await import("tsup");
|
|
655
661
|
const isDependenciesCacheOutdate = await this.checkDependenciesCacheOutdate();
|
|
656
|
-
const { sourcemap } = defu(options, { sourcemap: true });
|
|
657
662
|
let packNpmRelationList = [];
|
|
658
663
|
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
659
664
|
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
@@ -696,7 +701,7 @@ var CompilerContext = class {
|
|
|
696
701
|
logger_default.success(`${dep} \u4F9D\u8D56\u672A\u53D1\u751F\u53D8\u5316\uFF0C\u8DF3\u8FC7\u5904\u7406!`);
|
|
697
702
|
continue;
|
|
698
703
|
}
|
|
699
|
-
|
|
704
|
+
const mergedOptions = defu(options, {
|
|
700
705
|
entry: {
|
|
701
706
|
index: require2.resolve(dep)
|
|
702
707
|
},
|
|
@@ -709,9 +714,17 @@ var CompilerContext = class {
|
|
|
709
714
|
js: ".js"
|
|
710
715
|
};
|
|
711
716
|
},
|
|
712
|
-
sourcemap
|
|
717
|
+
sourcemap: false
|
|
713
718
|
// clean: false,
|
|
714
719
|
});
|
|
720
|
+
const resolvedOptions = this.inlineConfig.weapp?.npm?.tsup?.(mergedOptions);
|
|
721
|
+
let finalOptions;
|
|
722
|
+
if (resolvedOptions === void 0) {
|
|
723
|
+
finalOptions = mergedOptions;
|
|
724
|
+
} else if (isObject2(resolvedOptions)) {
|
|
725
|
+
finalOptions = resolvedOptions;
|
|
726
|
+
}
|
|
727
|
+
finalOptions && await tsupBuild(finalOptions);
|
|
715
728
|
}
|
|
716
729
|
logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
|
|
717
730
|
}
|
package/dist/cli.cjs
CHANGED
|
@@ -22,17 +22,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
-
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.
|
|
25
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
|
|
26
26
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
27
27
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
28
28
|
|
|
29
29
|
// src/cli.ts
|
|
30
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
30
31
|
var import_init = require("@weapp-core/init");
|
|
31
32
|
var import_cac = require("cac");
|
|
33
|
+
var import_vite3 = require("vite");
|
|
32
34
|
var import_weapp_ide_cli = require("weapp-ide-cli");
|
|
33
35
|
|
|
34
36
|
// package.json
|
|
35
|
-
var version = "1.
|
|
37
|
+
var version = "1.5.0";
|
|
36
38
|
|
|
37
39
|
// src/constants.ts
|
|
38
40
|
var VERSION = version;
|
|
@@ -42,11 +44,10 @@ var supportedCssLangs = ["wxss", "scss", "less", "sass", "styl"];
|
|
|
42
44
|
// src/context.ts
|
|
43
45
|
var import_node_module = require("module");
|
|
44
46
|
var import_node_process = __toESM(require("process"), 1);
|
|
45
|
-
var
|
|
47
|
+
var import_shared2 = require("@weapp-core/shared");
|
|
46
48
|
var import_chokidar = require("chokidar");
|
|
47
49
|
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
48
50
|
var import_pathe5 = __toESM(require("pathe"), 1);
|
|
49
|
-
var import_tsup = require("tsup");
|
|
50
51
|
var import_vite2 = require("vite");
|
|
51
52
|
var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
|
|
52
53
|
|
|
@@ -200,6 +201,9 @@ function resolveJson(entry, aliasEntries) {
|
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
}
|
|
204
|
+
if (Reflect.has(json, "$schema")) {
|
|
205
|
+
delete json.$schema;
|
|
206
|
+
}
|
|
203
207
|
return stringifyJson(json);
|
|
204
208
|
}
|
|
205
209
|
}
|
|
@@ -207,14 +211,14 @@ function resolveJson(entry, aliasEntries) {
|
|
|
207
211
|
// src/utils/projectConfig.ts
|
|
208
212
|
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
209
213
|
var import_pathe3 = __toESM(require("pathe"), 1);
|
|
210
|
-
function getProjectConfig(root, options) {
|
|
214
|
+
async function getProjectConfig(root, options) {
|
|
211
215
|
const baseJsonPath = import_pathe3.default.resolve(root, "project.config.json");
|
|
212
216
|
const privateJsonPath = import_pathe3.default.resolve(root, "project.private.config.json");
|
|
213
217
|
let baseJson = {};
|
|
214
218
|
let privateJson = {};
|
|
215
|
-
if (import_fs_extra3.default.
|
|
219
|
+
if (await import_fs_extra3.default.exists(baseJsonPath)) {
|
|
216
220
|
try {
|
|
217
|
-
baseJson = import_fs_extra3.default.
|
|
221
|
+
baseJson = await import_fs_extra3.default.readJson(baseJsonPath) || {};
|
|
218
222
|
} catch {
|
|
219
223
|
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
|
|
220
224
|
}
|
|
@@ -222,9 +226,9 @@ function getProjectConfig(root, options) {
|
|
|
222
226
|
throw new Error(`\u5728 ${root} \u76EE\u5F55\u4E0B\u627E\u4E0D\u5230 project.config.json`);
|
|
223
227
|
}
|
|
224
228
|
if (!options?.ignorePrivate) {
|
|
225
|
-
if (import_fs_extra3.default.
|
|
229
|
+
if (await import_fs_extra3.default.exists(privateJsonPath)) {
|
|
226
230
|
try {
|
|
227
|
-
privateJson = import_fs_extra3.default.
|
|
231
|
+
privateJson = await import_fs_extra3.default.readJson(privateJsonPath) || {};
|
|
228
232
|
} catch {
|
|
229
233
|
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.private.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
|
|
230
234
|
}
|
|
@@ -234,7 +238,6 @@ function getProjectConfig(root, options) {
|
|
|
234
238
|
}
|
|
235
239
|
|
|
236
240
|
// src/utils/scan.ts
|
|
237
|
-
var import_shared2 = require("@weapp-core/shared");
|
|
238
241
|
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
239
242
|
|
|
240
243
|
// src/plugins/parse.ts
|
|
@@ -358,10 +361,11 @@ function vitePluginWeapp(ctx, subPackageMeta) {
|
|
|
358
361
|
},
|
|
359
362
|
async load(id) {
|
|
360
363
|
if (entriesSet.has(id)) {
|
|
361
|
-
const
|
|
364
|
+
const code = await import_fs_extra5.default.readFile(id, "utf8");
|
|
365
|
+
const ms = new import_magic_string.default(code);
|
|
362
366
|
for (const ext of supportedCssLangs) {
|
|
363
367
|
const mayBeCssPath = changeFileExtension(id, ext);
|
|
364
|
-
if (import_fs_extra5.default.
|
|
368
|
+
if (await import_fs_extra5.default.exists(mayBeCssPath)) {
|
|
365
369
|
this.addWatchFile(mayBeCssPath);
|
|
366
370
|
ms.prepend(`import '${mayBeCssPath}'
|
|
367
371
|
`);
|
|
@@ -464,7 +468,7 @@ var CompilerContext = class {
|
|
|
464
468
|
subPackageMeta;
|
|
465
469
|
aliasEntries;
|
|
466
470
|
constructor(options) {
|
|
467
|
-
const { cwd, isDev, inlineConfig, projectConfig, mode, packageJson } = (0,
|
|
471
|
+
const { cwd, isDev, inlineConfig, projectConfig, mode, packageJson } = (0, import_shared2.defu)(options, {
|
|
468
472
|
cwd: import_node_process.default.cwd(),
|
|
469
473
|
isDev: false,
|
|
470
474
|
projectConfig: {},
|
|
@@ -499,7 +503,7 @@ var CompilerContext = class {
|
|
|
499
503
|
*
|
|
500
504
|
*/
|
|
501
505
|
get mpDistRoot() {
|
|
502
|
-
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot
|
|
506
|
+
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot;
|
|
503
507
|
}
|
|
504
508
|
async internalDev(inlineConfig) {
|
|
505
509
|
const watcher = await (0, import_vite2.build)(
|
|
@@ -537,7 +541,7 @@ var CompilerContext = class {
|
|
|
537
541
|
});
|
|
538
542
|
return watcher2;
|
|
539
543
|
};
|
|
540
|
-
const { paths, ...opts } = (0,
|
|
544
|
+
const { paths, ...opts } = (0, import_shared2.defu)(
|
|
541
545
|
inlineConfig.weapp?.watch,
|
|
542
546
|
{
|
|
543
547
|
ignored: [
|
|
@@ -553,7 +557,7 @@ var CompilerContext = class {
|
|
|
553
557
|
}
|
|
554
558
|
getConfig(subPackageMeta, ...configs) {
|
|
555
559
|
if (this.isDev) {
|
|
556
|
-
return (0,
|
|
560
|
+
return (0, import_shared2.defu)(
|
|
557
561
|
this.inlineConfig,
|
|
558
562
|
...configs,
|
|
559
563
|
{
|
|
@@ -576,7 +580,7 @@ var CompilerContext = class {
|
|
|
576
580
|
}
|
|
577
581
|
);
|
|
578
582
|
} else {
|
|
579
|
-
const inlineConfig = (0,
|
|
583
|
+
const inlineConfig = (0, import_shared2.defu)(
|
|
580
584
|
this.inlineConfig,
|
|
581
585
|
...configs,
|
|
582
586
|
{
|
|
@@ -605,8 +609,11 @@ var CompilerContext = class {
|
|
|
605
609
|
}
|
|
606
610
|
}
|
|
607
611
|
async loadDefaultConfig() {
|
|
608
|
-
const projectConfig = getProjectConfig(this.cwd);
|
|
612
|
+
const projectConfig = await getProjectConfig(this.cwd);
|
|
609
613
|
this.projectConfig = projectConfig;
|
|
614
|
+
if (!this.mpDistRoot) {
|
|
615
|
+
throw new Error("\u8BF7\u5728 `project.config.json` \u91CC\u8BBE\u7F6E `miniprogramRoot`, \u6BD4\u5982\u53EF\u4EE5\u8BBE\u7F6E\u4E3A `dist/` ");
|
|
616
|
+
}
|
|
610
617
|
const packageJsonPath = import_pathe5.default.resolve(this.cwd, "package.json");
|
|
611
618
|
const external = [];
|
|
612
619
|
if (await import_fs_extra6.default.exists(packageJsonPath)) {
|
|
@@ -622,7 +629,7 @@ var CompilerContext = class {
|
|
|
622
629
|
command: this.isDev ? "serve" : "build",
|
|
623
630
|
mode: this.mode
|
|
624
631
|
}, void 0, this.cwd);
|
|
625
|
-
this.inlineConfig = (0,
|
|
632
|
+
this.inlineConfig = (0, import_shared2.defu)({
|
|
626
633
|
configFile: false
|
|
627
634
|
}, loaded?.config, {
|
|
628
635
|
build: {
|
|
@@ -633,11 +640,11 @@ var CompilerContext = class {
|
|
|
633
640
|
entryFileNames: (chunkInfo) => {
|
|
634
641
|
const name = this.relativeSrcRoot(chunkInfo.name);
|
|
635
642
|
if (name.endsWith(".ts")) {
|
|
636
|
-
const baseFileName = (0,
|
|
643
|
+
const baseFileName = (0, import_shared2.removeExtension)(name);
|
|
637
644
|
if (baseFileName.endsWith(".wxs")) {
|
|
638
645
|
return baseFileName;
|
|
639
646
|
}
|
|
640
|
-
return (0,
|
|
647
|
+
return (0, import_shared2.addExtension)(baseFileName, ".js");
|
|
641
648
|
}
|
|
642
649
|
return name;
|
|
643
650
|
}
|
|
@@ -661,7 +668,7 @@ var CompilerContext = class {
|
|
|
661
668
|
return import_pathe5.default.resolve(this.cwd, "node_modules/weapp-vite/.cache/npm.json");
|
|
662
669
|
}
|
|
663
670
|
get dependenciesCacheHash() {
|
|
664
|
-
return (0,
|
|
671
|
+
return (0, import_shared2.objectHash)(this.packageJson.dependencies ?? {});
|
|
665
672
|
}
|
|
666
673
|
writeDependenciesCache() {
|
|
667
674
|
return import_fs_extra6.default.outputJSON(this.dependenciesCacheFilePath, {
|
|
@@ -675,7 +682,7 @@ var CompilerContext = class {
|
|
|
675
682
|
}
|
|
676
683
|
async checkDependenciesCacheOutdate() {
|
|
677
684
|
const json = await this.readDependenciesCache();
|
|
678
|
-
if ((0,
|
|
685
|
+
if ((0, import_shared2.isObject)(json)) {
|
|
679
686
|
return this.dependenciesCacheHash !== json["/"];
|
|
680
687
|
}
|
|
681
688
|
return true;
|
|
@@ -685,8 +692,8 @@ var CompilerContext = class {
|
|
|
685
692
|
// miniprogram
|
|
686
693
|
// https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
|
|
687
694
|
async buildNpm(options) {
|
|
695
|
+
const { build: tsupBuild } = await import("tsup");
|
|
688
696
|
const isDependenciesCacheOutdate = await this.checkDependenciesCacheOutdate();
|
|
689
|
-
const { sourcemap } = (0, import_shared3.defu)(options, { sourcemap: true });
|
|
690
697
|
let packNpmRelationList = [];
|
|
691
698
|
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
692
699
|
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
@@ -729,7 +736,7 @@ var CompilerContext = class {
|
|
|
729
736
|
logger_default.success(`${dep} \u4F9D\u8D56\u672A\u53D1\u751F\u53D8\u5316\uFF0C\u8DF3\u8FC7\u5904\u7406!`);
|
|
730
737
|
continue;
|
|
731
738
|
}
|
|
732
|
-
|
|
739
|
+
const mergedOptions = (0, import_shared2.defu)(options, {
|
|
733
740
|
entry: {
|
|
734
741
|
index: require2.resolve(dep)
|
|
735
742
|
},
|
|
@@ -742,9 +749,17 @@ var CompilerContext = class {
|
|
|
742
749
|
js: ".js"
|
|
743
750
|
};
|
|
744
751
|
},
|
|
745
|
-
sourcemap
|
|
752
|
+
sourcemap: false
|
|
746
753
|
// clean: false,
|
|
747
754
|
});
|
|
755
|
+
const resolvedOptions = this.inlineConfig.weapp?.npm?.tsup?.(mergedOptions);
|
|
756
|
+
let finalOptions;
|
|
757
|
+
if (resolvedOptions === void 0) {
|
|
758
|
+
finalOptions = mergedOptions;
|
|
759
|
+
} else if ((0, import_shared2.isObject)(resolvedOptions)) {
|
|
760
|
+
finalOptions = resolvedOptions;
|
|
761
|
+
}
|
|
762
|
+
finalOptions && await tsupBuild(finalOptions);
|
|
748
763
|
}
|
|
749
764
|
logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
|
|
750
765
|
}
|
|
@@ -762,7 +777,7 @@ var CompilerContext = class {
|
|
|
762
777
|
continue;
|
|
763
778
|
}
|
|
764
779
|
const tokens = componentUrl.split("/");
|
|
765
|
-
if (tokens[0] && (0,
|
|
780
|
+
if (tokens[0] && (0, import_shared2.isObject)(this.packageJson.dependencies) && Reflect.has(this.packageJson.dependencies, tokens[0])) {
|
|
766
781
|
continue;
|
|
767
782
|
} else if (tokens[0] === "") {
|
|
768
783
|
await this.scanComponentEntry(componentUrl.substring(1), import_pathe5.default.resolve(this.cwd, this.srcRoot));
|
|
@@ -785,7 +800,7 @@ var CompilerContext = class {
|
|
|
785
800
|
const appEntryPath = await findJsEntry(appConfigFile);
|
|
786
801
|
if (appEntryPath && await import_fs_extra6.default.exists(appConfigFile)) {
|
|
787
802
|
const config = await readCommentJson(appConfigFile);
|
|
788
|
-
if ((0,
|
|
803
|
+
if ((0, import_shared2.isObject)(config)) {
|
|
789
804
|
this.entriesSet.add(appEntryPath);
|
|
790
805
|
const appEntry = {
|
|
791
806
|
path: appEntryPath,
|
|
@@ -862,7 +877,7 @@ var CompilerContext = class {
|
|
|
862
877
|
partialEntry.json = jsonFragment.json;
|
|
863
878
|
partialEntry.jsonPath = jsonFragment.jsonPath;
|
|
864
879
|
}
|
|
865
|
-
if ((0,
|
|
880
|
+
if ((0, import_shared2.isObject)(config)) {
|
|
866
881
|
await this.usingComponentsHandler(jsonFragment, import_pathe5.default.dirname(configFile));
|
|
867
882
|
}
|
|
868
883
|
}
|
|
@@ -915,8 +930,73 @@ async function createCompilerContext(options) {
|
|
|
915
930
|
return ctx;
|
|
916
931
|
}
|
|
917
932
|
|
|
933
|
+
// src/schematics.ts
|
|
934
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
935
|
+
var import_schematics = require("@weapp-core/schematics");
|
|
936
|
+
var import_shared3 = require("@weapp-core/shared");
|
|
937
|
+
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
938
|
+
var import_pathe6 = __toESM(require("pathe"), 1);
|
|
939
|
+
function composePath(outDir, filename) {
|
|
940
|
+
return `${outDir}${outDir ? "/" : ""}${filename}`;
|
|
941
|
+
}
|
|
942
|
+
var defaultExtensions = {
|
|
943
|
+
js: "js",
|
|
944
|
+
json: "json",
|
|
945
|
+
wxml: "wxml",
|
|
946
|
+
wxss: "wxss"
|
|
947
|
+
};
|
|
948
|
+
function resolveExtension(extension) {
|
|
949
|
+
return extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
|
|
950
|
+
}
|
|
951
|
+
async function generate(options) {
|
|
952
|
+
let { fileName, outDir, extensions, type, cwd } = (0, import_shared3.defu)(options, {
|
|
953
|
+
// fileName: 'index',
|
|
954
|
+
type: "component",
|
|
955
|
+
extensions: {
|
|
956
|
+
...defaultExtensions
|
|
957
|
+
},
|
|
958
|
+
cwd: import_node_process2.default.cwd()
|
|
959
|
+
});
|
|
960
|
+
if (fileName === void 0) {
|
|
961
|
+
fileName = import_pathe6.default.basename(outDir);
|
|
962
|
+
}
|
|
963
|
+
const basepath = import_pathe6.default.resolve(cwd, outDir);
|
|
964
|
+
const targetFileTypes = ["js", "wxss", "json"];
|
|
965
|
+
if (type !== "app") {
|
|
966
|
+
targetFileTypes.push("wxml");
|
|
967
|
+
}
|
|
968
|
+
const files = targetFileTypes.map((x) => {
|
|
969
|
+
let code;
|
|
970
|
+
if (x === "js") {
|
|
971
|
+
code = (0, import_schematics.generateJs)(type);
|
|
972
|
+
} else if (x === "wxss") {
|
|
973
|
+
code = (0, import_schematics.generateWxss)();
|
|
974
|
+
} else if (x === "wxml") {
|
|
975
|
+
code = (0, import_schematics.generateWxml)();
|
|
976
|
+
} else if (x === "json") {
|
|
977
|
+
code = JSON.stringify((0, import_schematics.generateJson)(type), void 0, 2);
|
|
978
|
+
}
|
|
979
|
+
return {
|
|
980
|
+
fileName: `${fileName}${resolveExtension(extensions[x] ?? defaultExtensions[x])}`,
|
|
981
|
+
code
|
|
982
|
+
};
|
|
983
|
+
});
|
|
984
|
+
for (const { code, fileName: fileName2 } of files) {
|
|
985
|
+
if (code !== void 0) {
|
|
986
|
+
await import_fs_extra7.default.outputFile(import_pathe6.default.resolve(basepath, fileName2), code, "utf8");
|
|
987
|
+
logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
918
992
|
// src/cli.ts
|
|
919
993
|
var cli = (0, import_cac.cac)("weapp-vite");
|
|
994
|
+
function loadConfig() {
|
|
995
|
+
return (0, import_vite3.loadConfigFromFile)({
|
|
996
|
+
command: "serve",
|
|
997
|
+
mode: "development"
|
|
998
|
+
}, void 0, import_node_process3.default.cwd());
|
|
999
|
+
}
|
|
920
1000
|
function filterDuplicateOptions(options) {
|
|
921
1001
|
for (const [key, value] of Object.entries(options)) {
|
|
922
1002
|
if (Array.isArray(value)) {
|
|
@@ -941,7 +1021,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
|
|
|
941
1021
|
isDev: true
|
|
942
1022
|
});
|
|
943
1023
|
if (!options.skipNpm) {
|
|
944
|
-
await ctx.buildNpm();
|
|
1024
|
+
await ctx.buildNpm({ sourcemap: true });
|
|
945
1025
|
}
|
|
946
1026
|
await ctx.build();
|
|
947
1027
|
});
|
|
@@ -962,12 +1042,12 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
962
1042
|
});
|
|
963
1043
|
await ctx.build();
|
|
964
1044
|
if (!options.skipNpm) {
|
|
965
|
-
await ctx.buildNpm(
|
|
1045
|
+
await ctx.buildNpm();
|
|
966
1046
|
}
|
|
967
1047
|
});
|
|
968
|
-
cli.command("init").action(() => {
|
|
1048
|
+
cli.command("init").action(async () => {
|
|
969
1049
|
try {
|
|
970
|
-
(0, import_init.initConfig)({
|
|
1050
|
+
await (0, import_init.initConfig)({
|
|
971
1051
|
command: "weapp-vite"
|
|
972
1052
|
});
|
|
973
1053
|
} catch (error) {
|
|
@@ -988,6 +1068,50 @@ cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
|
|
|
988
1068
|
logger_default.error(error);
|
|
989
1069
|
}
|
|
990
1070
|
});
|
|
1071
|
+
cli.command("gc [filepath]", "generate component").alias("g").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
1072
|
+
const config = await loadConfig();
|
|
1073
|
+
let type = "component";
|
|
1074
|
+
let fileName = options.name;
|
|
1075
|
+
if (options.app) {
|
|
1076
|
+
type = "app";
|
|
1077
|
+
if (filepath === void 0) {
|
|
1078
|
+
filepath = "";
|
|
1079
|
+
}
|
|
1080
|
+
fileName = "app";
|
|
1081
|
+
}
|
|
1082
|
+
if (filepath === void 0) {
|
|
1083
|
+
logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
if (options.page) {
|
|
1087
|
+
type = "page";
|
|
1088
|
+
}
|
|
1089
|
+
await generate({
|
|
1090
|
+
outDir: filepath,
|
|
1091
|
+
type,
|
|
1092
|
+
fileName,
|
|
1093
|
+
extensions: config?.config.weapp?.generate?.extensions
|
|
1094
|
+
});
|
|
1095
|
+
});
|
|
1096
|
+
cli.command("ga [filepath]", "generate app").action(async (filepath) => {
|
|
1097
|
+
const config = await loadConfig();
|
|
1098
|
+
await generate({
|
|
1099
|
+
outDir: filepath ?? "",
|
|
1100
|
+
type: "app",
|
|
1101
|
+
fileName: "app",
|
|
1102
|
+
extensions: config?.config.weapp?.generate?.extensions
|
|
1103
|
+
});
|
|
1104
|
+
});
|
|
1105
|
+
cli.command("gp <filepath>", "generate page").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
1106
|
+
const config = await loadConfig();
|
|
1107
|
+
const fileName = options.name;
|
|
1108
|
+
await generate({
|
|
1109
|
+
outDir: filepath,
|
|
1110
|
+
type: "page",
|
|
1111
|
+
fileName,
|
|
1112
|
+
extensions: config?.config.weapp?.generate?.extensions
|
|
1113
|
+
});
|
|
1114
|
+
});
|
|
991
1115
|
cli.help();
|
|
992
1116
|
cli.version(VERSION);
|
|
993
1117
|
cli.parse();
|
package/dist/cli.mjs
CHANGED
|
@@ -2,14 +2,83 @@ import {
|
|
|
2
2
|
VERSION,
|
|
3
3
|
createCompilerContext,
|
|
4
4
|
logger_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-SKX4EDQU.mjs";
|
|
6
6
|
import "./chunk-444MQSSG.mjs";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
|
+
import process2 from "node:process";
|
|
9
10
|
import { initConfig } from "@weapp-core/init";
|
|
10
11
|
import { cac } from "cac";
|
|
12
|
+
import { loadConfigFromFile } from "vite";
|
|
11
13
|
import { parse } from "weapp-ide-cli";
|
|
14
|
+
|
|
15
|
+
// src/schematics.ts
|
|
16
|
+
import process from "node:process";
|
|
17
|
+
import { generateJs, generateJson, generateWxml, generateWxss } from "@weapp-core/schematics";
|
|
18
|
+
import { defu } from "@weapp-core/shared";
|
|
19
|
+
import fs from "fs-extra";
|
|
20
|
+
import path from "pathe";
|
|
21
|
+
function composePath(outDir, filename) {
|
|
22
|
+
return `${outDir}${outDir ? "/" : ""}${filename}`;
|
|
23
|
+
}
|
|
24
|
+
var defaultExtensions = {
|
|
25
|
+
js: "js",
|
|
26
|
+
json: "json",
|
|
27
|
+
wxml: "wxml",
|
|
28
|
+
wxss: "wxss"
|
|
29
|
+
};
|
|
30
|
+
function resolveExtension(extension) {
|
|
31
|
+
return extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
|
|
32
|
+
}
|
|
33
|
+
async function generate(options) {
|
|
34
|
+
let { fileName, outDir, extensions, type, cwd } = defu(options, {
|
|
35
|
+
// fileName: 'index',
|
|
36
|
+
type: "component",
|
|
37
|
+
extensions: {
|
|
38
|
+
...defaultExtensions
|
|
39
|
+
},
|
|
40
|
+
cwd: process.cwd()
|
|
41
|
+
});
|
|
42
|
+
if (fileName === void 0) {
|
|
43
|
+
fileName = path.basename(outDir);
|
|
44
|
+
}
|
|
45
|
+
const basepath = path.resolve(cwd, outDir);
|
|
46
|
+
const targetFileTypes = ["js", "wxss", "json"];
|
|
47
|
+
if (type !== "app") {
|
|
48
|
+
targetFileTypes.push("wxml");
|
|
49
|
+
}
|
|
50
|
+
const files = targetFileTypes.map((x) => {
|
|
51
|
+
let code;
|
|
52
|
+
if (x === "js") {
|
|
53
|
+
code = generateJs(type);
|
|
54
|
+
} else if (x === "wxss") {
|
|
55
|
+
code = generateWxss();
|
|
56
|
+
} else if (x === "wxml") {
|
|
57
|
+
code = generateWxml();
|
|
58
|
+
} else if (x === "json") {
|
|
59
|
+
code = JSON.stringify(generateJson(type), void 0, 2);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
fileName: `${fileName}${resolveExtension(extensions[x] ?? defaultExtensions[x])}`,
|
|
63
|
+
code
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
for (const { code, fileName: fileName2 } of files) {
|
|
67
|
+
if (code !== void 0) {
|
|
68
|
+
await fs.outputFile(path.resolve(basepath, fileName2), code, "utf8");
|
|
69
|
+
logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/cli.ts
|
|
12
75
|
var cli = cac("weapp-vite");
|
|
76
|
+
function loadConfig() {
|
|
77
|
+
return loadConfigFromFile({
|
|
78
|
+
command: "serve",
|
|
79
|
+
mode: "development"
|
|
80
|
+
}, void 0, process2.cwd());
|
|
81
|
+
}
|
|
13
82
|
function filterDuplicateOptions(options) {
|
|
14
83
|
for (const [key, value] of Object.entries(options)) {
|
|
15
84
|
if (Array.isArray(value)) {
|
|
@@ -34,7 +103,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
|
|
|
34
103
|
isDev: true
|
|
35
104
|
});
|
|
36
105
|
if (!options.skipNpm) {
|
|
37
|
-
await ctx.buildNpm();
|
|
106
|
+
await ctx.buildNpm({ sourcemap: true });
|
|
38
107
|
}
|
|
39
108
|
await ctx.build();
|
|
40
109
|
});
|
|
@@ -55,12 +124,12 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
55
124
|
});
|
|
56
125
|
await ctx.build();
|
|
57
126
|
if (!options.skipNpm) {
|
|
58
|
-
await ctx.buildNpm(
|
|
127
|
+
await ctx.buildNpm();
|
|
59
128
|
}
|
|
60
129
|
});
|
|
61
|
-
cli.command("init").action(() => {
|
|
130
|
+
cli.command("init").action(async () => {
|
|
62
131
|
try {
|
|
63
|
-
initConfig({
|
|
132
|
+
await initConfig({
|
|
64
133
|
command: "weapp-vite"
|
|
65
134
|
});
|
|
66
135
|
} catch (error) {
|
|
@@ -81,6 +150,50 @@ cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
|
|
|
81
150
|
logger_default.error(error);
|
|
82
151
|
}
|
|
83
152
|
});
|
|
153
|
+
cli.command("gc [filepath]", "generate component").alias("g").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
154
|
+
const config = await loadConfig();
|
|
155
|
+
let type = "component";
|
|
156
|
+
let fileName = options.name;
|
|
157
|
+
if (options.app) {
|
|
158
|
+
type = "app";
|
|
159
|
+
if (filepath === void 0) {
|
|
160
|
+
filepath = "";
|
|
161
|
+
}
|
|
162
|
+
fileName = "app";
|
|
163
|
+
}
|
|
164
|
+
if (filepath === void 0) {
|
|
165
|
+
logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (options.page) {
|
|
169
|
+
type = "page";
|
|
170
|
+
}
|
|
171
|
+
await generate({
|
|
172
|
+
outDir: filepath,
|
|
173
|
+
type,
|
|
174
|
+
fileName,
|
|
175
|
+
extensions: config?.config.weapp?.generate?.extensions
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
cli.command("ga [filepath]", "generate app").action(async (filepath) => {
|
|
179
|
+
const config = await loadConfig();
|
|
180
|
+
await generate({
|
|
181
|
+
outDir: filepath ?? "",
|
|
182
|
+
type: "app",
|
|
183
|
+
fileName: "app",
|
|
184
|
+
extensions: config?.config.weapp?.generate?.extensions
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
cli.command("gp <filepath>", "generate page").option("-n, --name <name>", "filename").action(async (filepath, options) => {
|
|
188
|
+
const config = await loadConfig();
|
|
189
|
+
const fileName = options.name;
|
|
190
|
+
await generate({
|
|
191
|
+
outDir: filepath,
|
|
192
|
+
type: "page",
|
|
193
|
+
fileName,
|
|
194
|
+
extensions: config?.config.weapp?.generate?.extensions
|
|
195
|
+
});
|
|
196
|
+
});
|
|
84
197
|
cli.help();
|
|
85
198
|
cli.version(VERSION);
|
|
86
199
|
cli.parse();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InlineConfig, UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
|
|
2
2
|
import { WatchOptions as WatchOptions$1 } from 'chokidar';
|
|
3
3
|
import { PackageJson } from 'pkg-types';
|
|
4
|
+
import { Options } from 'tsup';
|
|
4
5
|
|
|
5
6
|
interface Alias {
|
|
6
7
|
find: string | RegExp;
|
|
@@ -39,6 +40,23 @@ interface WeappViteConfig {
|
|
|
39
40
|
* json 配置文件别名
|
|
40
41
|
*/
|
|
41
42
|
jsonAlias?: AliasOptions;
|
|
43
|
+
/**
|
|
44
|
+
* 构建 npm 相关的配置
|
|
45
|
+
*/
|
|
46
|
+
npm?: {
|
|
47
|
+
tsup?: (options: Options) => Options;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* weapp-vite generate 相关的配置
|
|
51
|
+
*/
|
|
52
|
+
generate?: {
|
|
53
|
+
extensions?: Partial<{
|
|
54
|
+
js: string;
|
|
55
|
+
json: string;
|
|
56
|
+
wxml: string;
|
|
57
|
+
wxss: string;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
42
60
|
}
|
|
43
61
|
interface Entry {
|
|
44
62
|
path: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InlineConfig, UserConfig, UserConfigFnObject, UserConfigExport } from 'vite';
|
|
2
2
|
import { WatchOptions as WatchOptions$1 } from 'chokidar';
|
|
3
3
|
import { PackageJson } from 'pkg-types';
|
|
4
|
+
import { Options } from 'tsup';
|
|
4
5
|
|
|
5
6
|
interface Alias {
|
|
6
7
|
find: string | RegExp;
|
|
@@ -39,6 +40,23 @@ interface WeappViteConfig {
|
|
|
39
40
|
* json 配置文件别名
|
|
40
41
|
*/
|
|
41
42
|
jsonAlias?: AliasOptions;
|
|
43
|
+
/**
|
|
44
|
+
* 构建 npm 相关的配置
|
|
45
|
+
*/
|
|
46
|
+
npm?: {
|
|
47
|
+
tsup?: (options: Options) => Options;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* weapp-vite generate 相关的配置
|
|
51
|
+
*/
|
|
52
|
+
generate?: {
|
|
53
|
+
extensions?: Partial<{
|
|
54
|
+
js: string;
|
|
55
|
+
json: string;
|
|
56
|
+
wxml: string;
|
|
57
|
+
wxss: string;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
42
60
|
}
|
|
43
61
|
interface Entry {
|
|
44
62
|
path: string;
|
package/dist/config.d.cts
CHANGED
package/dist/config.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -35,18 +35,17 @@ __export(src_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
37
|
|
|
38
|
-
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.
|
|
38
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
|
|
39
39
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
40
40
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
41
41
|
|
|
42
42
|
// src/context.ts
|
|
43
43
|
var import_node_module = require("module");
|
|
44
44
|
var import_node_process = __toESM(require("process"), 1);
|
|
45
|
-
var
|
|
45
|
+
var import_shared2 = require("@weapp-core/shared");
|
|
46
46
|
var import_chokidar = require("chokidar");
|
|
47
47
|
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
48
48
|
var import_pathe5 = __toESM(require("pathe"), 1);
|
|
49
|
-
var import_tsup = require("tsup");
|
|
50
49
|
var import_vite2 = require("vite");
|
|
51
50
|
var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
|
|
52
51
|
|
|
@@ -204,6 +203,9 @@ function resolveJson(entry, aliasEntries) {
|
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
205
|
}
|
|
206
|
+
if (Reflect.has(json, "$schema")) {
|
|
207
|
+
delete json.$schema;
|
|
208
|
+
}
|
|
207
209
|
return stringifyJson(json);
|
|
208
210
|
}
|
|
209
211
|
}
|
|
@@ -211,14 +213,14 @@ function resolveJson(entry, aliasEntries) {
|
|
|
211
213
|
// src/utils/projectConfig.ts
|
|
212
214
|
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
213
215
|
var import_pathe3 = __toESM(require("pathe"), 1);
|
|
214
|
-
function getProjectConfig(root, options) {
|
|
216
|
+
async function getProjectConfig(root, options) {
|
|
215
217
|
const baseJsonPath = import_pathe3.default.resolve(root, "project.config.json");
|
|
216
218
|
const privateJsonPath = import_pathe3.default.resolve(root, "project.private.config.json");
|
|
217
219
|
let baseJson = {};
|
|
218
220
|
let privateJson = {};
|
|
219
|
-
if (import_fs_extra3.default.
|
|
221
|
+
if (await import_fs_extra3.default.exists(baseJsonPath)) {
|
|
220
222
|
try {
|
|
221
|
-
baseJson = import_fs_extra3.default.
|
|
223
|
+
baseJson = await import_fs_extra3.default.readJson(baseJsonPath) || {};
|
|
222
224
|
} catch {
|
|
223
225
|
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
|
|
224
226
|
}
|
|
@@ -226,9 +228,9 @@ function getProjectConfig(root, options) {
|
|
|
226
228
|
throw new Error(`\u5728 ${root} \u76EE\u5F55\u4E0B\u627E\u4E0D\u5230 project.config.json`);
|
|
227
229
|
}
|
|
228
230
|
if (!options?.ignorePrivate) {
|
|
229
|
-
if (import_fs_extra3.default.
|
|
231
|
+
if (await import_fs_extra3.default.exists(privateJsonPath)) {
|
|
230
232
|
try {
|
|
231
|
-
privateJson = import_fs_extra3.default.
|
|
233
|
+
privateJson = await import_fs_extra3.default.readJson(privateJsonPath) || {};
|
|
232
234
|
} catch {
|
|
233
235
|
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.private.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
|
|
234
236
|
}
|
|
@@ -238,7 +240,6 @@ function getProjectConfig(root, options) {
|
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
// src/utils/scan.ts
|
|
241
|
-
var import_shared2 = require("@weapp-core/shared");
|
|
242
243
|
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
243
244
|
|
|
244
245
|
// src/plugins/parse.ts
|
|
@@ -362,10 +363,11 @@ function vitePluginWeapp(ctx, subPackageMeta) {
|
|
|
362
363
|
},
|
|
363
364
|
async load(id) {
|
|
364
365
|
if (entriesSet.has(id)) {
|
|
365
|
-
const
|
|
366
|
+
const code = await import_fs_extra5.default.readFile(id, "utf8");
|
|
367
|
+
const ms = new import_magic_string.default(code);
|
|
366
368
|
for (const ext of supportedCssLangs) {
|
|
367
369
|
const mayBeCssPath = changeFileExtension(id, ext);
|
|
368
|
-
if (import_fs_extra5.default.
|
|
370
|
+
if (await import_fs_extra5.default.exists(mayBeCssPath)) {
|
|
369
371
|
this.addWatchFile(mayBeCssPath);
|
|
370
372
|
ms.prepend(`import '${mayBeCssPath}'
|
|
371
373
|
`);
|
|
@@ -468,7 +470,7 @@ var CompilerContext = class {
|
|
|
468
470
|
subPackageMeta;
|
|
469
471
|
aliasEntries;
|
|
470
472
|
constructor(options) {
|
|
471
|
-
const { cwd, isDev, inlineConfig, projectConfig, mode, packageJson } = (0,
|
|
473
|
+
const { cwd, isDev, inlineConfig, projectConfig, mode, packageJson } = (0, import_shared2.defu)(options, {
|
|
472
474
|
cwd: import_node_process.default.cwd(),
|
|
473
475
|
isDev: false,
|
|
474
476
|
projectConfig: {},
|
|
@@ -503,7 +505,7 @@ var CompilerContext = class {
|
|
|
503
505
|
*
|
|
504
506
|
*/
|
|
505
507
|
get mpDistRoot() {
|
|
506
|
-
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot
|
|
508
|
+
return this.projectConfig.miniprogramRoot || this.projectConfig.srcMiniprogramRoot;
|
|
507
509
|
}
|
|
508
510
|
async internalDev(inlineConfig) {
|
|
509
511
|
const watcher = await (0, import_vite2.build)(
|
|
@@ -541,7 +543,7 @@ var CompilerContext = class {
|
|
|
541
543
|
});
|
|
542
544
|
return watcher2;
|
|
543
545
|
};
|
|
544
|
-
const { paths, ...opts } = (0,
|
|
546
|
+
const { paths, ...opts } = (0, import_shared2.defu)(
|
|
545
547
|
inlineConfig.weapp?.watch,
|
|
546
548
|
{
|
|
547
549
|
ignored: [
|
|
@@ -557,7 +559,7 @@ var CompilerContext = class {
|
|
|
557
559
|
}
|
|
558
560
|
getConfig(subPackageMeta, ...configs) {
|
|
559
561
|
if (this.isDev) {
|
|
560
|
-
return (0,
|
|
562
|
+
return (0, import_shared2.defu)(
|
|
561
563
|
this.inlineConfig,
|
|
562
564
|
...configs,
|
|
563
565
|
{
|
|
@@ -580,7 +582,7 @@ var CompilerContext = class {
|
|
|
580
582
|
}
|
|
581
583
|
);
|
|
582
584
|
} else {
|
|
583
|
-
const inlineConfig = (0,
|
|
585
|
+
const inlineConfig = (0, import_shared2.defu)(
|
|
584
586
|
this.inlineConfig,
|
|
585
587
|
...configs,
|
|
586
588
|
{
|
|
@@ -609,8 +611,11 @@ var CompilerContext = class {
|
|
|
609
611
|
}
|
|
610
612
|
}
|
|
611
613
|
async loadDefaultConfig() {
|
|
612
|
-
const projectConfig = getProjectConfig(this.cwd);
|
|
614
|
+
const projectConfig = await getProjectConfig(this.cwd);
|
|
613
615
|
this.projectConfig = projectConfig;
|
|
616
|
+
if (!this.mpDistRoot) {
|
|
617
|
+
throw new Error("\u8BF7\u5728 `project.config.json` \u91CC\u8BBE\u7F6E `miniprogramRoot`, \u6BD4\u5982\u53EF\u4EE5\u8BBE\u7F6E\u4E3A `dist/` ");
|
|
618
|
+
}
|
|
614
619
|
const packageJsonPath = import_pathe5.default.resolve(this.cwd, "package.json");
|
|
615
620
|
const external = [];
|
|
616
621
|
if (await import_fs_extra6.default.exists(packageJsonPath)) {
|
|
@@ -626,7 +631,7 @@ var CompilerContext = class {
|
|
|
626
631
|
command: this.isDev ? "serve" : "build",
|
|
627
632
|
mode: this.mode
|
|
628
633
|
}, void 0, this.cwd);
|
|
629
|
-
this.inlineConfig = (0,
|
|
634
|
+
this.inlineConfig = (0, import_shared2.defu)({
|
|
630
635
|
configFile: false
|
|
631
636
|
}, loaded?.config, {
|
|
632
637
|
build: {
|
|
@@ -637,11 +642,11 @@ var CompilerContext = class {
|
|
|
637
642
|
entryFileNames: (chunkInfo) => {
|
|
638
643
|
const name = this.relativeSrcRoot(chunkInfo.name);
|
|
639
644
|
if (name.endsWith(".ts")) {
|
|
640
|
-
const baseFileName = (0,
|
|
645
|
+
const baseFileName = (0, import_shared2.removeExtension)(name);
|
|
641
646
|
if (baseFileName.endsWith(".wxs")) {
|
|
642
647
|
return baseFileName;
|
|
643
648
|
}
|
|
644
|
-
return (0,
|
|
649
|
+
return (0, import_shared2.addExtension)(baseFileName, ".js");
|
|
645
650
|
}
|
|
646
651
|
return name;
|
|
647
652
|
}
|
|
@@ -665,7 +670,7 @@ var CompilerContext = class {
|
|
|
665
670
|
return import_pathe5.default.resolve(this.cwd, "node_modules/weapp-vite/.cache/npm.json");
|
|
666
671
|
}
|
|
667
672
|
get dependenciesCacheHash() {
|
|
668
|
-
return (0,
|
|
673
|
+
return (0, import_shared2.objectHash)(this.packageJson.dependencies ?? {});
|
|
669
674
|
}
|
|
670
675
|
writeDependenciesCache() {
|
|
671
676
|
return import_fs_extra6.default.outputJSON(this.dependenciesCacheFilePath, {
|
|
@@ -679,7 +684,7 @@ var CompilerContext = class {
|
|
|
679
684
|
}
|
|
680
685
|
async checkDependenciesCacheOutdate() {
|
|
681
686
|
const json = await this.readDependenciesCache();
|
|
682
|
-
if ((0,
|
|
687
|
+
if ((0, import_shared2.isObject)(json)) {
|
|
683
688
|
return this.dependenciesCacheHash !== json["/"];
|
|
684
689
|
}
|
|
685
690
|
return true;
|
|
@@ -689,8 +694,8 @@ var CompilerContext = class {
|
|
|
689
694
|
// miniprogram
|
|
690
695
|
// https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
|
|
691
696
|
async buildNpm(options) {
|
|
697
|
+
const { build: tsupBuild } = await import("tsup");
|
|
692
698
|
const isDependenciesCacheOutdate = await this.checkDependenciesCacheOutdate();
|
|
693
|
-
const { sourcemap } = (0, import_shared3.defu)(options, { sourcemap: true });
|
|
694
699
|
let packNpmRelationList = [];
|
|
695
700
|
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
696
701
|
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
@@ -733,7 +738,7 @@ var CompilerContext = class {
|
|
|
733
738
|
logger_default.success(`${dep} \u4F9D\u8D56\u672A\u53D1\u751F\u53D8\u5316\uFF0C\u8DF3\u8FC7\u5904\u7406!`);
|
|
734
739
|
continue;
|
|
735
740
|
}
|
|
736
|
-
|
|
741
|
+
const mergedOptions = (0, import_shared2.defu)(options, {
|
|
737
742
|
entry: {
|
|
738
743
|
index: require2.resolve(dep)
|
|
739
744
|
},
|
|
@@ -746,9 +751,17 @@ var CompilerContext = class {
|
|
|
746
751
|
js: ".js"
|
|
747
752
|
};
|
|
748
753
|
},
|
|
749
|
-
sourcemap
|
|
754
|
+
sourcemap: false
|
|
750
755
|
// clean: false,
|
|
751
756
|
});
|
|
757
|
+
const resolvedOptions = this.inlineConfig.weapp?.npm?.tsup?.(mergedOptions);
|
|
758
|
+
let finalOptions;
|
|
759
|
+
if (resolvedOptions === void 0) {
|
|
760
|
+
finalOptions = mergedOptions;
|
|
761
|
+
} else if ((0, import_shared2.isObject)(resolvedOptions)) {
|
|
762
|
+
finalOptions = resolvedOptions;
|
|
763
|
+
}
|
|
764
|
+
finalOptions && await tsupBuild(finalOptions);
|
|
752
765
|
}
|
|
753
766
|
logger_default.success(`${dep} \u4F9D\u8D56\u5904\u7406\u5B8C\u6210!`);
|
|
754
767
|
}
|
|
@@ -766,7 +779,7 @@ var CompilerContext = class {
|
|
|
766
779
|
continue;
|
|
767
780
|
}
|
|
768
781
|
const tokens = componentUrl.split("/");
|
|
769
|
-
if (tokens[0] && (0,
|
|
782
|
+
if (tokens[0] && (0, import_shared2.isObject)(this.packageJson.dependencies) && Reflect.has(this.packageJson.dependencies, tokens[0])) {
|
|
770
783
|
continue;
|
|
771
784
|
} else if (tokens[0] === "") {
|
|
772
785
|
await this.scanComponentEntry(componentUrl.substring(1), import_pathe5.default.resolve(this.cwd, this.srcRoot));
|
|
@@ -789,7 +802,7 @@ var CompilerContext = class {
|
|
|
789
802
|
const appEntryPath = await findJsEntry(appConfigFile);
|
|
790
803
|
if (appEntryPath && await import_fs_extra6.default.exists(appConfigFile)) {
|
|
791
804
|
const config = await readCommentJson(appConfigFile);
|
|
792
|
-
if ((0,
|
|
805
|
+
if ((0, import_shared2.isObject)(config)) {
|
|
793
806
|
this.entriesSet.add(appEntryPath);
|
|
794
807
|
const appEntry = {
|
|
795
808
|
path: appEntryPath,
|
|
@@ -866,7 +879,7 @@ var CompilerContext = class {
|
|
|
866
879
|
partialEntry.json = jsonFragment.json;
|
|
867
880
|
partialEntry.jsonPath = jsonFragment.jsonPath;
|
|
868
881
|
}
|
|
869
|
-
if ((0,
|
|
882
|
+
if ((0, import_shared2.isObject)(config)) {
|
|
870
883
|
await this.usingComponentsHandler(jsonFragment, import_pathe5.default.dirname(configFile));
|
|
871
884
|
}
|
|
872
885
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FSWatcher } from 'chokidar';
|
|
2
2
|
import { PackageJson } from 'pkg-types';
|
|
3
3
|
import { RollupOutput, RollupWatcher } from 'rollup';
|
|
4
|
-
import { P as ProjectConfig, E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-
|
|
4
|
+
import { P as ProjectConfig, E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-wDAzBoFy.cjs';
|
|
5
5
|
import { InlineConfig } from 'vite';
|
|
6
|
+
import { Options } from 'tsup';
|
|
6
7
|
|
|
7
8
|
declare class CompilerContext {
|
|
8
9
|
/**
|
|
@@ -14,7 +15,7 @@ declare class CompilerContext {
|
|
|
14
15
|
projectConfig: ProjectConfig;
|
|
15
16
|
mode: string;
|
|
16
17
|
packageJson: PackageJson;
|
|
17
|
-
fsWatcherMap
|
|
18
|
+
private fsWatcherMap;
|
|
18
19
|
private rollupWatcherMap;
|
|
19
20
|
entriesSet: Set<string>;
|
|
20
21
|
entries: Entry[];
|
|
@@ -29,7 +30,7 @@ declare class CompilerContext {
|
|
|
29
30
|
* 默认为 'dist'
|
|
30
31
|
*
|
|
31
32
|
*/
|
|
32
|
-
get mpDistRoot(): string;
|
|
33
|
+
get mpDistRoot(): string | undefined;
|
|
33
34
|
private internalDev;
|
|
34
35
|
runDev(): Promise<FSWatcher>;
|
|
35
36
|
getConfig(subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig>[]): InlineConfig;
|
|
@@ -41,9 +42,7 @@ declare class CompilerContext {
|
|
|
41
42
|
writeDependenciesCache(): Promise<void>;
|
|
42
43
|
readDependenciesCache(): Promise<any>;
|
|
43
44
|
checkDependenciesCacheOutdate(): Promise<boolean>;
|
|
44
|
-
buildNpm(options?:
|
|
45
|
-
sourcemap?: boolean;
|
|
46
|
-
}): Promise<void>;
|
|
45
|
+
buildNpm(options?: Options): Promise<void>;
|
|
47
46
|
private usingComponentsHandler;
|
|
48
47
|
resetEntries(): void;
|
|
49
48
|
scanAppEntry(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FSWatcher } from 'chokidar';
|
|
2
2
|
import { PackageJson } from 'pkg-types';
|
|
3
3
|
import { RollupOutput, RollupWatcher } from 'rollup';
|
|
4
|
-
import { P as ProjectConfig, E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-
|
|
4
|
+
import { P as ProjectConfig, E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, C as CompilerContextOptions } from './config-wDAzBoFy.js';
|
|
5
5
|
import { InlineConfig } from 'vite';
|
|
6
|
+
import { Options } from 'tsup';
|
|
6
7
|
|
|
7
8
|
declare class CompilerContext {
|
|
8
9
|
/**
|
|
@@ -14,7 +15,7 @@ declare class CompilerContext {
|
|
|
14
15
|
projectConfig: ProjectConfig;
|
|
15
16
|
mode: string;
|
|
16
17
|
packageJson: PackageJson;
|
|
17
|
-
fsWatcherMap
|
|
18
|
+
private fsWatcherMap;
|
|
18
19
|
private rollupWatcherMap;
|
|
19
20
|
entriesSet: Set<string>;
|
|
20
21
|
entries: Entry[];
|
|
@@ -29,7 +30,7 @@ declare class CompilerContext {
|
|
|
29
30
|
* 默认为 'dist'
|
|
30
31
|
*
|
|
31
32
|
*/
|
|
32
|
-
get mpDistRoot(): string;
|
|
33
|
+
get mpDistRoot(): string | undefined;
|
|
33
34
|
private internalDev;
|
|
34
35
|
runDev(): Promise<FSWatcher>;
|
|
35
36
|
getConfig(subPackageMeta?: SubPackageMetaValue, ...configs: Partial<InlineConfig>[]): InlineConfig;
|
|
@@ -41,9 +42,7 @@ declare class CompilerContext {
|
|
|
41
42
|
writeDependenciesCache(): Promise<void>;
|
|
42
43
|
readDependenciesCache(): Promise<any>;
|
|
43
44
|
checkDependenciesCacheOutdate(): Promise<boolean>;
|
|
44
|
-
buildNpm(options?:
|
|
45
|
-
sourcemap?: boolean;
|
|
46
|
-
}): Promise<void>;
|
|
45
|
+
buildNpm(options?: Options): Promise<void>;
|
|
47
46
|
private usingComponentsHandler;
|
|
48
47
|
resetEntries(): void;
|
|
49
48
|
scanAppEntry(): Promise<void>;
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"bin": {
|
|
41
41
|
"weapp-vite": "bin/weapp-vite.js",
|
|
42
42
|
"weapp-vite-esm": "bin/weapp-vite-esm.js",
|
|
43
|
-
"weapp-vite-cjs": "bin/weapp-vite-cjs.js"
|
|
43
|
+
"weapp-vite-cjs": "bin/weapp-vite-cjs.js",
|
|
44
|
+
"wv": "bin/weapp-vite.js"
|
|
44
45
|
},
|
|
45
46
|
"files": [
|
|
46
47
|
"bin",
|
|
@@ -61,9 +62,10 @@
|
|
|
61
62
|
"picomatch": "^4.0.2",
|
|
62
63
|
"tsup": "^8.3.0",
|
|
63
64
|
"vite-tsconfig-paths": "^5.0.1",
|
|
64
|
-
"@weapp-core/init": "^1.0.
|
|
65
|
-
"@weapp-core/shared": "^1.0.3",
|
|
65
|
+
"@weapp-core/init": "^1.0.9",
|
|
66
66
|
"@weapp-core/logger": "^1.0.1",
|
|
67
|
+
"@weapp-core/schematics": "^1.0.0",
|
|
68
|
+
"@weapp-core/shared": "^1.0.3",
|
|
67
69
|
"weapp-ide-cli": "^2.0.6"
|
|
68
70
|
},
|
|
69
71
|
"publishConfig": {
|