weapp-vite 0.0.2-alpha.0 → 0.0.2-alpha.1
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.cjs +82 -43
- package/dist/cli.js +87 -48
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var import_init = require("@weapp-core/init");
|
|
|
31
31
|
var import_vite2 = require("vite");
|
|
32
32
|
var import_micromatch = __toESM(require("micromatch"), 1);
|
|
33
33
|
var import_shared3 = require("@weapp-core/shared");
|
|
34
|
+
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
34
35
|
|
|
35
36
|
// src/utils/scan.ts
|
|
36
37
|
var import_pathe = __toESM(require("pathe"), 1);
|
|
@@ -50,13 +51,10 @@ function searchAppEntry(root) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
function removeFileExtension(path3) {
|
|
54
|
-
return path3.replace(/\.[^/.]+$/, "");
|
|
55
|
-
}
|
|
56
54
|
function searchPageEntry(wxmlPath) {
|
|
57
55
|
if (import_fs_extra.default.existsSync(wxmlPath)) {
|
|
58
56
|
const extensions = ["js", "ts"];
|
|
59
|
-
const base =
|
|
57
|
+
const base = (0, import_shared.removeExtension)(wxmlPath);
|
|
60
58
|
for (const ext of extensions) {
|
|
61
59
|
const entryPath = (0, import_shared.addExtension)(base, `.${ext}`);
|
|
62
60
|
if (import_fs_extra.default.existsSync(entryPath)) {
|
|
@@ -68,12 +66,15 @@ function searchPageEntry(wxmlPath) {
|
|
|
68
66
|
function getWxmlEntry(wxmlPath) {
|
|
69
67
|
const pageEntry = searchPageEntry(wxmlPath);
|
|
70
68
|
if (pageEntry) {
|
|
71
|
-
const jsonPath = (0, import_shared.addExtension)(
|
|
72
|
-
if (import_fs_extra.default.existsSync(jsonPath)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
const jsonPath = (0, import_shared.addExtension)((0, import_shared.removeExtension)(wxmlPath), ".json");
|
|
70
|
+
if (import_fs_extra.default.existsSync(jsonPath)) {
|
|
71
|
+
const json = import_fs_extra.default.readJsonSync(jsonPath, { throws: false });
|
|
72
|
+
if (json && json.component) {
|
|
73
|
+
return {
|
|
74
|
+
path: pageEntry,
|
|
75
|
+
type: "component"
|
|
76
|
+
};
|
|
77
|
+
}
|
|
77
78
|
}
|
|
78
79
|
return {
|
|
79
80
|
path: pageEntry,
|
|
@@ -154,14 +155,14 @@ function vitePluginWeapp(options) {
|
|
|
154
155
|
const { cwd: cwd2, entries: _entries, src } = (0, import_shared2.defu)(options, {
|
|
155
156
|
src: ""
|
|
156
157
|
});
|
|
158
|
+
function relative(p) {
|
|
159
|
+
return import_node_path.default.relative(cwd2, p);
|
|
160
|
+
}
|
|
157
161
|
const input = _entries.reduce((acc, cur) => {
|
|
158
162
|
acc[relative(cur)] = cur;
|
|
159
163
|
return acc;
|
|
160
164
|
}, {});
|
|
161
165
|
const entries = Array.isArray(_entries) ? new Set(_entries) : _entries;
|
|
162
|
-
function relative(p) {
|
|
163
|
-
return import_node_path.default.relative(cwd2, p);
|
|
164
|
-
}
|
|
165
166
|
const stylesIds = /* @__PURE__ */ new Set();
|
|
166
167
|
let configResolved;
|
|
167
168
|
return [
|
|
@@ -170,14 +171,6 @@ function vitePluginWeapp(options) {
|
|
|
170
171
|
enforce: "pre",
|
|
171
172
|
configResolved(config) {
|
|
172
173
|
config.build.rollupOptions.input = input;
|
|
173
|
-
config.build.rollupOptions.output = {
|
|
174
|
-
format: "cjs",
|
|
175
|
-
entryFileNames: (chunkInfo) => {
|
|
176
|
-
return chunkInfo.name;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
config.build.assetsDir = ".";
|
|
180
|
-
config.build.commonjsOptions.transformMixedEsModules = true;
|
|
181
174
|
configResolved = config;
|
|
182
175
|
},
|
|
183
176
|
resolveId(source) {
|
|
@@ -192,10 +185,12 @@ function vitePluginWeapp(options) {
|
|
|
192
185
|
for (const ext of supportedCssExtensions) {
|
|
193
186
|
const mayBeCssPath = (0, import_shared2.addExtension)(base, ext);
|
|
194
187
|
if (import_fs_extra2.default.existsSync(mayBeCssPath)) {
|
|
188
|
+
this.addWatchFile(mayBeCssPath);
|
|
195
189
|
ms.prepend(`import '${mayBeCssPath}'
|
|
196
190
|
`);
|
|
197
191
|
}
|
|
198
192
|
}
|
|
193
|
+
this.addWatchFile(id);
|
|
199
194
|
return {
|
|
200
195
|
code: ms.toString()
|
|
201
196
|
};
|
|
@@ -240,13 +235,19 @@ function vitePluginWeapp(options) {
|
|
|
240
235
|
}
|
|
241
236
|
);
|
|
242
237
|
for (const file of files) {
|
|
238
|
+
const filepath = import_node_path.default.resolve(cwd2, file);
|
|
239
|
+
this.addWatchFile(filepath);
|
|
243
240
|
this.emitFile({
|
|
244
241
|
type: "asset",
|
|
245
242
|
fileName: file,
|
|
246
|
-
source: await import_fs_extra2.default.readFile(
|
|
243
|
+
source: await import_fs_extra2.default.readFile(filepath)
|
|
247
244
|
});
|
|
248
245
|
}
|
|
249
246
|
}
|
|
247
|
+
// generateBundle(_options, _bundle) {
|
|
248
|
+
// const files = this.getWatchFiles()
|
|
249
|
+
// console.log(files)
|
|
250
|
+
// },
|
|
250
251
|
},
|
|
251
252
|
{
|
|
252
253
|
name: "weapp-vite"
|
|
@@ -262,6 +263,8 @@ function vitePluginWeapp(options) {
|
|
|
262
263
|
function createFilter(include, exclude, options) {
|
|
263
264
|
const opts = (0, import_shared3.defu)(options, {
|
|
264
265
|
ignore: exclude
|
|
266
|
+
// dot: true,
|
|
267
|
+
// contains: true,
|
|
265
268
|
});
|
|
266
269
|
return function(id) {
|
|
267
270
|
if (typeof id !== "string") {
|
|
@@ -273,37 +276,73 @@ function createFilter(include, exclude, options) {
|
|
|
273
276
|
return import_micromatch.default.isMatch(id, include, opts);
|
|
274
277
|
};
|
|
275
278
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
+
function getEntries(options) {
|
|
280
|
+
let cwd2;
|
|
281
|
+
let relative;
|
|
282
|
+
if (typeof options === "string") {
|
|
283
|
+
cwd2 = options;
|
|
284
|
+
} else {
|
|
285
|
+
cwd2 = options.cwd;
|
|
286
|
+
relative = options.relative;
|
|
287
|
+
}
|
|
288
|
+
const filter = createFilter(["**/*"], [...defaultExcluded, import_pathe2.default.resolve(cwd2, "dist/**")], { cwd: cwd2 });
|
|
289
|
+
return scanEntries(cwd2, { filter, relative });
|
|
290
|
+
}
|
|
291
|
+
function getDefaultConfig(options) {
|
|
292
|
+
return {
|
|
293
|
+
build: {
|
|
294
|
+
rollupOptions: {
|
|
295
|
+
output: {
|
|
296
|
+
format: "cjs",
|
|
297
|
+
entryFileNames: (chunkInfo) => {
|
|
298
|
+
return chunkInfo.name;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
assetsDir: ".",
|
|
303
|
+
commonjsOptions: {
|
|
304
|
+
transformMixedEsModules: true,
|
|
305
|
+
include: void 0
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
plugins: [
|
|
309
|
+
vitePluginWeapp(options)
|
|
310
|
+
]
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
async function runDev(cwd2, options) {
|
|
314
|
+
const entries = await getEntries(cwd2);
|
|
279
315
|
if (entries) {
|
|
280
|
-
const watcher = await (0, import_vite2.build)(
|
|
281
|
-
|
|
282
|
-
|
|
316
|
+
const watcher = await (0, import_vite2.build)(
|
|
317
|
+
(0, import_shared3.defu)(
|
|
318
|
+
options,
|
|
319
|
+
getDefaultConfig({
|
|
283
320
|
cwd: cwd2,
|
|
284
321
|
entries: entries.all
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
322
|
+
}),
|
|
323
|
+
{
|
|
324
|
+
build: {
|
|
325
|
+
watch: {},
|
|
326
|
+
minify: false
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
)
|
|
330
|
+
);
|
|
292
331
|
return watcher;
|
|
293
332
|
}
|
|
294
333
|
}
|
|
295
|
-
async function runProd(cwd2) {
|
|
296
|
-
const
|
|
297
|
-
const entries = await scanEntries(cwd2, { filter });
|
|
334
|
+
async function runProd(cwd2, options) {
|
|
335
|
+
const entries = await getEntries(cwd2);
|
|
298
336
|
if (entries) {
|
|
299
|
-
const output = await (0, import_vite2.build)(
|
|
300
|
-
|
|
301
|
-
|
|
337
|
+
const output = await (0, import_vite2.build)(
|
|
338
|
+
(0, import_shared3.defu)(
|
|
339
|
+
options,
|
|
340
|
+
getDefaultConfig({
|
|
302
341
|
cwd: cwd2,
|
|
303
342
|
entries: entries.all
|
|
304
343
|
})
|
|
305
|
-
|
|
306
|
-
|
|
344
|
+
)
|
|
345
|
+
);
|
|
307
346
|
return output;
|
|
308
347
|
}
|
|
309
348
|
}
|
package/dist/cli.js
CHANGED
|
@@ -7,12 +7,13 @@ import { initConfig } from "@weapp-core/init";
|
|
|
7
7
|
import { build } from "vite";
|
|
8
8
|
import mm from "micromatch";
|
|
9
9
|
import { defu as defu2 } from "@weapp-core/shared";
|
|
10
|
+
import path3 from "pathe";
|
|
10
11
|
|
|
11
12
|
// src/utils/scan.ts
|
|
12
13
|
import path from "pathe";
|
|
13
14
|
import fs from "fs-extra";
|
|
14
15
|
import klaw from "klaw";
|
|
15
|
-
import { addExtension } from "@weapp-core/shared";
|
|
16
|
+
import { addExtension, removeExtension } from "@weapp-core/shared";
|
|
16
17
|
var defaultExcluded = ["**/node_modules/**", "**/miniprogram_npm/**"];
|
|
17
18
|
function searchAppEntry(root) {
|
|
18
19
|
const extensions = ["js", "ts"];
|
|
@@ -26,13 +27,10 @@ function searchAppEntry(root) {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
function removeFileExtension(path3) {
|
|
30
|
-
return path3.replace(/\.[^/.]+$/, "");
|
|
31
|
-
}
|
|
32
30
|
function searchPageEntry(wxmlPath) {
|
|
33
31
|
if (fs.existsSync(wxmlPath)) {
|
|
34
32
|
const extensions = ["js", "ts"];
|
|
35
|
-
const base =
|
|
33
|
+
const base = removeExtension(wxmlPath);
|
|
36
34
|
for (const ext of extensions) {
|
|
37
35
|
const entryPath = addExtension(base, `.${ext}`);
|
|
38
36
|
if (fs.existsSync(entryPath)) {
|
|
@@ -44,12 +42,15 @@ function searchPageEntry(wxmlPath) {
|
|
|
44
42
|
function getWxmlEntry(wxmlPath) {
|
|
45
43
|
const pageEntry = searchPageEntry(wxmlPath);
|
|
46
44
|
if (pageEntry) {
|
|
47
|
-
const jsonPath = addExtension(
|
|
48
|
-
if (fs.existsSync(jsonPath)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
const jsonPath = addExtension(removeExtension(wxmlPath), ".json");
|
|
46
|
+
if (fs.existsSync(jsonPath)) {
|
|
47
|
+
const json = fs.readJsonSync(jsonPath, { throws: false });
|
|
48
|
+
if (json && json.component) {
|
|
49
|
+
return {
|
|
50
|
+
path: pageEntry,
|
|
51
|
+
type: "component"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
55
|
return {
|
|
55
56
|
path: pageEntry,
|
|
@@ -103,7 +104,7 @@ var supportedCssExtensions = supportedCssLangs.map((x) => `.${x}`);
|
|
|
103
104
|
import path2 from "node:path";
|
|
104
105
|
import fs2 from "fs-extra";
|
|
105
106
|
import MagicString from "magic-string";
|
|
106
|
-
import { addExtension as addExtension2, defu, removeExtension } from "@weapp-core/shared";
|
|
107
|
+
import { addExtension as addExtension2, defu, removeExtension as removeExtension2 } from "@weapp-core/shared";
|
|
107
108
|
import fg from "fast-glob";
|
|
108
109
|
import { isCSSRequest, preprocessCSS } from "vite";
|
|
109
110
|
function parseRequest(id) {
|
|
@@ -118,11 +119,11 @@ function parseRequest(id) {
|
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
121
|
function normalizeCssPath(id) {
|
|
121
|
-
return addExtension2(
|
|
122
|
+
return addExtension2(removeExtension2(id), ".wxss");
|
|
122
123
|
}
|
|
123
124
|
function getRealPath(res) {
|
|
124
125
|
if (res.query.wxss) {
|
|
125
|
-
return addExtension2(
|
|
126
|
+
return addExtension2(removeExtension2(res.filename), ".wxss");
|
|
126
127
|
}
|
|
127
128
|
return res.filename;
|
|
128
129
|
}
|
|
@@ -130,14 +131,14 @@ function vitePluginWeapp(options) {
|
|
|
130
131
|
const { cwd: cwd2, entries: _entries, src } = defu(options, {
|
|
131
132
|
src: ""
|
|
132
133
|
});
|
|
134
|
+
function relative(p) {
|
|
135
|
+
return path2.relative(cwd2, p);
|
|
136
|
+
}
|
|
133
137
|
const input = _entries.reduce((acc, cur) => {
|
|
134
138
|
acc[relative(cur)] = cur;
|
|
135
139
|
return acc;
|
|
136
140
|
}, {});
|
|
137
141
|
const entries = Array.isArray(_entries) ? new Set(_entries) : _entries;
|
|
138
|
-
function relative(p) {
|
|
139
|
-
return path2.relative(cwd2, p);
|
|
140
|
-
}
|
|
141
142
|
const stylesIds = /* @__PURE__ */ new Set();
|
|
142
143
|
let configResolved;
|
|
143
144
|
return [
|
|
@@ -146,14 +147,6 @@ function vitePluginWeapp(options) {
|
|
|
146
147
|
enforce: "pre",
|
|
147
148
|
configResolved(config) {
|
|
148
149
|
config.build.rollupOptions.input = input;
|
|
149
|
-
config.build.rollupOptions.output = {
|
|
150
|
-
format: "cjs",
|
|
151
|
-
entryFileNames: (chunkInfo) => {
|
|
152
|
-
return chunkInfo.name;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
config.build.assetsDir = ".";
|
|
156
|
-
config.build.commonjsOptions.transformMixedEsModules = true;
|
|
157
150
|
configResolved = config;
|
|
158
151
|
},
|
|
159
152
|
resolveId(source) {
|
|
@@ -163,15 +156,17 @@ function vitePluginWeapp(options) {
|
|
|
163
156
|
},
|
|
164
157
|
load(id) {
|
|
165
158
|
if (entries.has(id)) {
|
|
166
|
-
const base =
|
|
159
|
+
const base = removeExtension2(id);
|
|
167
160
|
const ms = new MagicString(fs2.readFileSync(id, "utf8"));
|
|
168
161
|
for (const ext of supportedCssExtensions) {
|
|
169
162
|
const mayBeCssPath = addExtension2(base, ext);
|
|
170
163
|
if (fs2.existsSync(mayBeCssPath)) {
|
|
164
|
+
this.addWatchFile(mayBeCssPath);
|
|
171
165
|
ms.prepend(`import '${mayBeCssPath}'
|
|
172
166
|
`);
|
|
173
167
|
}
|
|
174
168
|
}
|
|
169
|
+
this.addWatchFile(id);
|
|
175
170
|
return {
|
|
176
171
|
code: ms.toString()
|
|
177
172
|
};
|
|
@@ -216,13 +211,19 @@ function vitePluginWeapp(options) {
|
|
|
216
211
|
}
|
|
217
212
|
);
|
|
218
213
|
for (const file of files) {
|
|
214
|
+
const filepath = path2.resolve(cwd2, file);
|
|
215
|
+
this.addWatchFile(filepath);
|
|
219
216
|
this.emitFile({
|
|
220
217
|
type: "asset",
|
|
221
218
|
fileName: file,
|
|
222
|
-
source: await fs2.readFile(
|
|
219
|
+
source: await fs2.readFile(filepath)
|
|
223
220
|
});
|
|
224
221
|
}
|
|
225
222
|
}
|
|
223
|
+
// generateBundle(_options, _bundle) {
|
|
224
|
+
// const files = this.getWatchFiles()
|
|
225
|
+
// console.log(files)
|
|
226
|
+
// },
|
|
226
227
|
},
|
|
227
228
|
{
|
|
228
229
|
name: "weapp-vite"
|
|
@@ -238,6 +239,8 @@ function vitePluginWeapp(options) {
|
|
|
238
239
|
function createFilter(include, exclude, options) {
|
|
239
240
|
const opts = defu2(options, {
|
|
240
241
|
ignore: exclude
|
|
242
|
+
// dot: true,
|
|
243
|
+
// contains: true,
|
|
241
244
|
});
|
|
242
245
|
return function(id) {
|
|
243
246
|
if (typeof id !== "string") {
|
|
@@ -249,37 +252,73 @@ function createFilter(include, exclude, options) {
|
|
|
249
252
|
return mm.isMatch(id, include, opts);
|
|
250
253
|
};
|
|
251
254
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
+
function getEntries(options) {
|
|
256
|
+
let cwd2;
|
|
257
|
+
let relative;
|
|
258
|
+
if (typeof options === "string") {
|
|
259
|
+
cwd2 = options;
|
|
260
|
+
} else {
|
|
261
|
+
cwd2 = options.cwd;
|
|
262
|
+
relative = options.relative;
|
|
263
|
+
}
|
|
264
|
+
const filter = createFilter(["**/*"], [...defaultExcluded, path3.resolve(cwd2, "dist/**")], { cwd: cwd2 });
|
|
265
|
+
return scanEntries(cwd2, { filter, relative });
|
|
266
|
+
}
|
|
267
|
+
function getDefaultConfig(options) {
|
|
268
|
+
return {
|
|
269
|
+
build: {
|
|
270
|
+
rollupOptions: {
|
|
271
|
+
output: {
|
|
272
|
+
format: "cjs",
|
|
273
|
+
entryFileNames: (chunkInfo) => {
|
|
274
|
+
return chunkInfo.name;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
assetsDir: ".",
|
|
279
|
+
commonjsOptions: {
|
|
280
|
+
transformMixedEsModules: true,
|
|
281
|
+
include: void 0
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
plugins: [
|
|
285
|
+
vitePluginWeapp(options)
|
|
286
|
+
]
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
async function runDev(cwd2, options) {
|
|
290
|
+
const entries = await getEntries(cwd2);
|
|
255
291
|
if (entries) {
|
|
256
|
-
const watcher = await build(
|
|
257
|
-
|
|
258
|
-
|
|
292
|
+
const watcher = await build(
|
|
293
|
+
defu2(
|
|
294
|
+
options,
|
|
295
|
+
getDefaultConfig({
|
|
259
296
|
cwd: cwd2,
|
|
260
297
|
entries: entries.all
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
298
|
+
}),
|
|
299
|
+
{
|
|
300
|
+
build: {
|
|
301
|
+
watch: {},
|
|
302
|
+
minify: false
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
);
|
|
268
307
|
return watcher;
|
|
269
308
|
}
|
|
270
309
|
}
|
|
271
|
-
async function runProd(cwd2) {
|
|
272
|
-
const
|
|
273
|
-
const entries = await scanEntries(cwd2, { filter });
|
|
310
|
+
async function runProd(cwd2, options) {
|
|
311
|
+
const entries = await getEntries(cwd2);
|
|
274
312
|
if (entries) {
|
|
275
|
-
const output = await build(
|
|
276
|
-
|
|
277
|
-
|
|
313
|
+
const output = await build(
|
|
314
|
+
defu2(
|
|
315
|
+
options,
|
|
316
|
+
getDefaultConfig({
|
|
278
317
|
cwd: cwd2,
|
|
279
318
|
entries: entries.all
|
|
280
319
|
})
|
|
281
|
-
|
|
282
|
-
|
|
320
|
+
)
|
|
321
|
+
);
|
|
283
322
|
return output;
|
|
284
323
|
}
|
|
285
324
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.2-alpha.
|
|
4
|
+
"version": "0.0.2-alpha.1",
|
|
5
5
|
"description": "WIP",
|
|
6
6
|
"author": "SonOfMagic <qq1324318532@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"magic-string": "^0.30.11",
|
|
39
39
|
"micromatch": "^4.0.7",
|
|
40
40
|
"pathe": "^1.1.2",
|
|
41
|
-
"@weapp-core/init": "^0.0.2-alpha.
|
|
42
|
-
"@weapp-core/shared": "^0.0.2-alpha.
|
|
41
|
+
"@weapp-core/init": "^0.0.2-alpha.1",
|
|
42
|
+
"@weapp-core/shared": "^0.0.2-alpha.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public",
|