weapp-vite 1.1.7 → 1.2.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-2E5WYTKQ.mjs → chunk-3EHL3BIF.mjs} +65 -1
- package/dist/cli.cjs +71 -1
- package/dist/cli.mjs +3 -1
- package/dist/index.cjs +68 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "1.
|
|
2
|
+
var version = "1.2.0";
|
|
3
3
|
|
|
4
4
|
// src/constants.ts
|
|
5
5
|
var VERSION = version;
|
|
6
6
|
var jsExtensions = ["js", "ts"];
|
|
7
7
|
|
|
8
8
|
// src/context.ts
|
|
9
|
+
import { createRequire } from "node:module";
|
|
9
10
|
import process2 from "node:process";
|
|
10
11
|
import { addExtension as addExtension3, defu as defu3, removeExtension as removeExtension3 } from "@weapp-core/shared";
|
|
11
12
|
import { watch } from "chokidar";
|
|
@@ -511,6 +512,7 @@ function vitePluginWeapp(ctx) {
|
|
|
511
512
|
}
|
|
512
513
|
|
|
513
514
|
// src/context.ts
|
|
515
|
+
var require2 = createRequire(import.meta.url);
|
|
514
516
|
var CompilerContext = class _CompilerContext {
|
|
515
517
|
inlineConfig;
|
|
516
518
|
cwd;
|
|
@@ -731,6 +733,68 @@ var CompilerContext = class _CompilerContext {
|
|
|
731
733
|
configFile: false
|
|
732
734
|
}, loaded?.config, this.inlineConfig);
|
|
733
735
|
}
|
|
736
|
+
// https://cn.vitejs.dev/guide/build.html#library-mode
|
|
737
|
+
// miniprogram_dist
|
|
738
|
+
// miniprogram
|
|
739
|
+
// 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
|
|
740
|
+
async buildNpm() {
|
|
741
|
+
let packNpmRelationList = [];
|
|
742
|
+
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
743
|
+
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
744
|
+
} else {
|
|
745
|
+
packNpmRelationList = [
|
|
746
|
+
{
|
|
747
|
+
miniprogramNpmDistDir: ".",
|
|
748
|
+
packageJsonPath: "./package.json"
|
|
749
|
+
}
|
|
750
|
+
];
|
|
751
|
+
}
|
|
752
|
+
for (const relation of packNpmRelationList) {
|
|
753
|
+
const packageJsonPath = path5.resolve(this.cwd, relation.packageJsonPath);
|
|
754
|
+
if (await fs4.exists(packageJsonPath)) {
|
|
755
|
+
const pkgJson = await fs4.readJson(packageJsonPath);
|
|
756
|
+
const outDir = path5.resolve(this.cwd, relation.miniprogramNpmDistDir, "miniprogram_npm");
|
|
757
|
+
if (pkgJson.dependencies) {
|
|
758
|
+
const dependencies = Object.keys(pkgJson.dependencies);
|
|
759
|
+
if (dependencies.length > 0) {
|
|
760
|
+
for (const dep of dependencies) {
|
|
761
|
+
const id = `${dep}/package.json`;
|
|
762
|
+
const targetJson = require2(id);
|
|
763
|
+
if ("miniprogram" in targetJson && targetJson.miniprogram) {
|
|
764
|
+
const targetJsonPath = require2.resolve(id);
|
|
765
|
+
await fs4.copy(
|
|
766
|
+
path5.resolve(
|
|
767
|
+
path5.dirname(targetJsonPath),
|
|
768
|
+
targetJson.miniprogram
|
|
769
|
+
),
|
|
770
|
+
path5.join(outDir, dep)
|
|
771
|
+
);
|
|
772
|
+
} else {
|
|
773
|
+
await build({
|
|
774
|
+
build: {
|
|
775
|
+
sourcemap: true,
|
|
776
|
+
outDir: path5.join(outDir, dep),
|
|
777
|
+
minify: false,
|
|
778
|
+
rollupOptions: {
|
|
779
|
+
input: {
|
|
780
|
+
index: require2.resolve(dep)
|
|
781
|
+
},
|
|
782
|
+
output: {
|
|
783
|
+
format: "cjs",
|
|
784
|
+
strict: false,
|
|
785
|
+
entryFileNames: "[name].js"
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
assetsDir: "."
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
734
798
|
};
|
|
735
799
|
|
|
736
800
|
export {
|
package/dist/cli.cjs
CHANGED
|
@@ -22,6 +22,10 @@ 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.0.0_postcss@8.4.47_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
|
|
26
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
27
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
28
|
+
|
|
25
29
|
// src/cli.ts
|
|
26
30
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
27
31
|
var import_init = require("@weapp-core/init");
|
|
@@ -29,13 +33,14 @@ var import_cac = require("cac");
|
|
|
29
33
|
var import_weapp_ide_cli = require("weapp-ide-cli");
|
|
30
34
|
|
|
31
35
|
// package.json
|
|
32
|
-
var version = "1.
|
|
36
|
+
var version = "1.2.0";
|
|
33
37
|
|
|
34
38
|
// src/constants.ts
|
|
35
39
|
var VERSION = version;
|
|
36
40
|
var jsExtensions = ["js", "ts"];
|
|
37
41
|
|
|
38
42
|
// src/context.ts
|
|
43
|
+
var import_node_module = require("module");
|
|
39
44
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
40
45
|
var import_shared4 = require("@weapp-core/shared");
|
|
41
46
|
var import_chokidar = require("chokidar");
|
|
@@ -541,6 +546,7 @@ function vitePluginWeapp(ctx) {
|
|
|
541
546
|
}
|
|
542
547
|
|
|
543
548
|
// src/context.ts
|
|
549
|
+
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
544
550
|
var CompilerContext = class _CompilerContext {
|
|
545
551
|
inlineConfig;
|
|
546
552
|
cwd;
|
|
@@ -761,6 +767,68 @@ var CompilerContext = class _CompilerContext {
|
|
|
761
767
|
configFile: false
|
|
762
768
|
}, loaded?.config, this.inlineConfig);
|
|
763
769
|
}
|
|
770
|
+
// https://cn.vitejs.dev/guide/build.html#library-mode
|
|
771
|
+
// miniprogram_dist
|
|
772
|
+
// miniprogram
|
|
773
|
+
// 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
|
|
774
|
+
async buildNpm() {
|
|
775
|
+
let packNpmRelationList = [];
|
|
776
|
+
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
777
|
+
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
778
|
+
} else {
|
|
779
|
+
packNpmRelationList = [
|
|
780
|
+
{
|
|
781
|
+
miniprogramNpmDistDir: ".",
|
|
782
|
+
packageJsonPath: "./package.json"
|
|
783
|
+
}
|
|
784
|
+
];
|
|
785
|
+
}
|
|
786
|
+
for (const relation of packNpmRelationList) {
|
|
787
|
+
const packageJsonPath = import_pathe5.default.resolve(this.cwd, relation.packageJsonPath);
|
|
788
|
+
if (await import_fs_extra4.default.exists(packageJsonPath)) {
|
|
789
|
+
const pkgJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
790
|
+
const outDir = import_pathe5.default.resolve(this.cwd, relation.miniprogramNpmDistDir, "miniprogram_npm");
|
|
791
|
+
if (pkgJson.dependencies) {
|
|
792
|
+
const dependencies = Object.keys(pkgJson.dependencies);
|
|
793
|
+
if (dependencies.length > 0) {
|
|
794
|
+
for (const dep of dependencies) {
|
|
795
|
+
const id = `${dep}/package.json`;
|
|
796
|
+
const targetJson = require2(id);
|
|
797
|
+
if ("miniprogram" in targetJson && targetJson.miniprogram) {
|
|
798
|
+
const targetJsonPath = require2.resolve(id);
|
|
799
|
+
await import_fs_extra4.default.copy(
|
|
800
|
+
import_pathe5.default.resolve(
|
|
801
|
+
import_pathe5.default.dirname(targetJsonPath),
|
|
802
|
+
targetJson.miniprogram
|
|
803
|
+
),
|
|
804
|
+
import_pathe5.default.join(outDir, dep)
|
|
805
|
+
);
|
|
806
|
+
} else {
|
|
807
|
+
await (0, import_vite2.build)({
|
|
808
|
+
build: {
|
|
809
|
+
sourcemap: true,
|
|
810
|
+
outDir: import_pathe5.default.join(outDir, dep),
|
|
811
|
+
minify: false,
|
|
812
|
+
rollupOptions: {
|
|
813
|
+
input: {
|
|
814
|
+
index: require2.resolve(dep)
|
|
815
|
+
},
|
|
816
|
+
output: {
|
|
817
|
+
format: "cjs",
|
|
818
|
+
strict: false,
|
|
819
|
+
entryFileNames: "[name].js"
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
assetsDir: "."
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
764
832
|
};
|
|
765
833
|
|
|
766
834
|
// src/logger.ts
|
|
@@ -793,6 +861,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").action(asy
|
|
|
793
861
|
isDev: true
|
|
794
862
|
});
|
|
795
863
|
await ctx.loadDefaultConfig();
|
|
864
|
+
await ctx.buildNpm();
|
|
796
865
|
await ctx.runDev();
|
|
797
866
|
});
|
|
798
867
|
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
|
|
@@ -811,6 +880,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
811
880
|
mode: options.mode
|
|
812
881
|
});
|
|
813
882
|
await ctx.loadDefaultConfig();
|
|
883
|
+
await ctx.buildNpm();
|
|
814
884
|
await ctx.runProd();
|
|
815
885
|
});
|
|
816
886
|
cli.command("init").action(() => {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompilerContext,
|
|
3
3
|
VERSION
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3EHL3BIF.mjs";
|
|
5
5
|
import "./chunk-444MQSSG.mjs";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
@@ -40,6 +40,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").action(asy
|
|
|
40
40
|
isDev: true
|
|
41
41
|
});
|
|
42
42
|
await ctx.loadDefaultConfig();
|
|
43
|
+
await ctx.buildNpm();
|
|
43
44
|
await ctx.runDev();
|
|
44
45
|
});
|
|
45
46
|
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
|
|
@@ -58,6 +59,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
|
|
|
58
59
|
mode: options.mode
|
|
59
60
|
});
|
|
60
61
|
await ctx.loadDefaultConfig();
|
|
62
|
+
await ctx.buildNpm();
|
|
61
63
|
await ctx.runProd();
|
|
62
64
|
});
|
|
63
65
|
cli.command("init").action(() => {
|
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,12 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.0.0_postcss@8.4.47_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
|
|
38
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
39
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
37
41
|
// src/context.ts
|
|
42
|
+
var import_node_module = require("module");
|
|
38
43
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
39
44
|
var import_shared4 = require("@weapp-core/shared");
|
|
40
45
|
var import_chokidar = require("chokidar");
|
|
@@ -543,6 +548,7 @@ function vitePluginWeapp(ctx) {
|
|
|
543
548
|
}
|
|
544
549
|
|
|
545
550
|
// src/context.ts
|
|
551
|
+
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
546
552
|
var CompilerContext = class _CompilerContext {
|
|
547
553
|
inlineConfig;
|
|
548
554
|
cwd;
|
|
@@ -763,6 +769,68 @@ var CompilerContext = class _CompilerContext {
|
|
|
763
769
|
configFile: false
|
|
764
770
|
}, loaded?.config, this.inlineConfig);
|
|
765
771
|
}
|
|
772
|
+
// https://cn.vitejs.dev/guide/build.html#library-mode
|
|
773
|
+
// miniprogram_dist
|
|
774
|
+
// miniprogram
|
|
775
|
+
// 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
|
|
776
|
+
async buildNpm() {
|
|
777
|
+
let packNpmRelationList = [];
|
|
778
|
+
if (this.projectConfig.setting?.packNpmManually && Array.isArray(this.projectConfig.setting.packNpmRelationList)) {
|
|
779
|
+
packNpmRelationList = this.projectConfig.setting.packNpmRelationList;
|
|
780
|
+
} else {
|
|
781
|
+
packNpmRelationList = [
|
|
782
|
+
{
|
|
783
|
+
miniprogramNpmDistDir: ".",
|
|
784
|
+
packageJsonPath: "./package.json"
|
|
785
|
+
}
|
|
786
|
+
];
|
|
787
|
+
}
|
|
788
|
+
for (const relation of packNpmRelationList) {
|
|
789
|
+
const packageJsonPath = import_pathe5.default.resolve(this.cwd, relation.packageJsonPath);
|
|
790
|
+
if (await import_fs_extra4.default.exists(packageJsonPath)) {
|
|
791
|
+
const pkgJson = await import_fs_extra4.default.readJson(packageJsonPath);
|
|
792
|
+
const outDir = import_pathe5.default.resolve(this.cwd, relation.miniprogramNpmDistDir, "miniprogram_npm");
|
|
793
|
+
if (pkgJson.dependencies) {
|
|
794
|
+
const dependencies = Object.keys(pkgJson.dependencies);
|
|
795
|
+
if (dependencies.length > 0) {
|
|
796
|
+
for (const dep of dependencies) {
|
|
797
|
+
const id = `${dep}/package.json`;
|
|
798
|
+
const targetJson = require2(id);
|
|
799
|
+
if ("miniprogram" in targetJson && targetJson.miniprogram) {
|
|
800
|
+
const targetJsonPath = require2.resolve(id);
|
|
801
|
+
await import_fs_extra4.default.copy(
|
|
802
|
+
import_pathe5.default.resolve(
|
|
803
|
+
import_pathe5.default.dirname(targetJsonPath),
|
|
804
|
+
targetJson.miniprogram
|
|
805
|
+
),
|
|
806
|
+
import_pathe5.default.join(outDir, dep)
|
|
807
|
+
);
|
|
808
|
+
} else {
|
|
809
|
+
await (0, import_vite2.build)({
|
|
810
|
+
build: {
|
|
811
|
+
sourcemap: true,
|
|
812
|
+
outDir: import_pathe5.default.join(outDir, dep),
|
|
813
|
+
minify: false,
|
|
814
|
+
rollupOptions: {
|
|
815
|
+
input: {
|
|
816
|
+
index: require2.resolve(dep)
|
|
817
|
+
},
|
|
818
|
+
output: {
|
|
819
|
+
format: "cjs",
|
|
820
|
+
strict: false,
|
|
821
|
+
entryFileNames: "[name].js"
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
assetsDir: "."
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
766
834
|
};
|
|
767
835
|
// Annotate the CommonJS export names for ESM import in node:
|
|
768
836
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,13 @@ import { InlineConfig } from 'vite';
|
|
|
7
7
|
interface ProjectConfig {
|
|
8
8
|
miniprogramRoot?: string;
|
|
9
9
|
srcMiniprogramRoot?: string;
|
|
10
|
+
setting?: {
|
|
11
|
+
packNpmManually?: boolean;
|
|
12
|
+
packNpmRelationList?: {
|
|
13
|
+
packageJsonPath: string;
|
|
14
|
+
miniprogramNpmDistDir: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
interface CompilerContextOptions {
|
|
@@ -41,6 +48,7 @@ declare class CompilerContext {
|
|
|
41
48
|
runProd(): Promise<RollupOutput | RollupOutput[]>;
|
|
42
49
|
build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[]>;
|
|
43
50
|
loadDefaultConfig(): Promise<void>;
|
|
51
|
+
buildNpm(): Promise<void>;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export { CompilerContext, type CompilerContextOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ import { InlineConfig } from 'vite';
|
|
|
7
7
|
interface ProjectConfig {
|
|
8
8
|
miniprogramRoot?: string;
|
|
9
9
|
srcMiniprogramRoot?: string;
|
|
10
|
+
setting?: {
|
|
11
|
+
packNpmManually?: boolean;
|
|
12
|
+
packNpmRelationList?: {
|
|
13
|
+
packageJsonPath: string;
|
|
14
|
+
miniprogramNpmDistDir: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
interface CompilerContextOptions {
|
|
@@ -41,6 +48,7 @@ declare class CompilerContext {
|
|
|
41
48
|
runProd(): Promise<RollupOutput | RollupOutput[]>;
|
|
42
49
|
build(): Promise<FSWatcher | undefined> | Promise<RollupOutput | RollupOutput[]>;
|
|
43
50
|
loadDefaultConfig(): Promise<void>;
|
|
51
|
+
buildNpm(): Promise<void>;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export { CompilerContext, type CompilerContextOptions };
|
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.2.0",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"picocolors": "^1.1.0",
|
|
64
64
|
"pkg-types": "^1.2.0",
|
|
65
65
|
"vite-tsconfig-paths": "^5.0.1",
|
|
66
|
-
"@weapp-core/init": "^1.0.4",
|
|
67
66
|
"@weapp-core/logger": "^1.0.1",
|
|
68
67
|
"@weapp-core/shared": "^1.0.1",
|
|
68
|
+
"@weapp-core/init": "^1.0.4",
|
|
69
69
|
"weapp-ide-cli": "^2.0.5"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|