weapp-vite 1.1.3 → 1.1.4

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.
@@ -24,7 +24,7 @@ import fg from "fast-glob";
24
24
  import fs3 from "fs-extra";
25
25
  import MagicString from "magic-string";
26
26
  import path4 from "pathe";
27
- import { isCSSRequest, preprocessCSS } from "vite";
27
+ import { isCSSRequest } from "vite";
28
28
 
29
29
  // src/debugger.ts
30
30
  import createDebug from "debug";
@@ -323,7 +323,6 @@ function getRealPath(res) {
323
323
  return res.filename;
324
324
  }
325
325
  function vitePluginWeapp(ctx) {
326
- const stylesIds = /* @__PURE__ */ new Set();
327
326
  let configResolved;
328
327
  let entriesSet = /* @__PURE__ */ new Set();
329
328
  function relative(p) {
@@ -440,7 +439,7 @@ function vitePluginWeapp(ctx) {
440
439
  return source.replace(/\.wxss$/, ".css?wxss");
441
440
  }
442
441
  },
443
- load(id) {
442
+ async load(id) {
444
443
  if (entriesSet.has(id)) {
445
444
  const base = removeExtension2(id);
446
445
  const ms = new MagicString(fs3.readFileSync(id, "utf8"));
@@ -457,41 +456,33 @@ function vitePluginWeapp(ctx) {
457
456
  code: ms.toString()
458
457
  };
459
458
  } else if (isCSSRequest(id)) {
460
- stylesIds.add(id);
461
- return {
462
- code: ""
463
- };
464
- }
465
- },
466
- async buildEnd() {
467
- const styles = {};
468
- for (const stylesId of stylesIds) {
469
- const parsed = parseRequest(stylesId);
459
+ const parsed = parseRequest(id);
470
460
  const realPath = getRealPath(parsed);
471
461
  if (await fs3.exists(realPath)) {
472
462
  const css = await fs3.readFile(realPath, "utf8");
473
- const res = await preprocessCSS(css, stylesId, configResolved);
474
- const fileName = relative(normalizeCssPath(stylesId));
475
- if (styles[fileName]) {
476
- styles[fileName] += res.code;
477
- } else {
478
- styles[fileName] = res.code;
479
- }
480
- } else {
481
- stylesIds.delete(stylesId);
463
+ return {
464
+ code: css
465
+ };
482
466
  }
483
467
  }
484
- for (const style of Object.entries(styles)) {
485
- this.emitFile({
486
- type: "asset",
487
- fileName: ctx.relativeSrcRoot(style[0]),
488
- source: style[1]
489
- });
468
+ },
469
+ generateBundle(_options, bundle) {
470
+ const bundleKeys = Object.keys(bundle);
471
+ for (const bundleKey of bundleKeys) {
472
+ const asset = bundle[bundleKey];
473
+ if (bundleKey.endsWith(".css") && asset.type === "asset" && asset.originalFileName?.endsWith(".js")) {
474
+ const newFileName = normalizeCssPath(asset.originalFileName);
475
+ this.emitFile({
476
+ type: "asset",
477
+ fileName: newFileName,
478
+ source: asset.source
479
+ });
480
+ delete bundle[bundleKey];
481
+ }
490
482
  }
491
483
  }
492
- // generateBundle(_options, _bundle) {
493
- // const files = this.getWatchFiles()
494
- // console.log(files)
484
+ // writeBundle(options, bundle) {
485
+ // console.log(options, bundle)
495
486
  // },
496
487
  },
497
488
  {
package/dist/cli.cjs CHANGED
@@ -29,7 +29,7 @@ var import_cac = require("cac");
29
29
  var import_weapp_ide_cli = require("weapp-ide-cli");
30
30
 
31
31
  // package.json
32
- var version = "1.1.3";
32
+ var version = "1.1.4";
33
33
 
34
34
  // src/constants.ts
35
35
  var VERSION = version;
@@ -359,7 +359,6 @@ function getRealPath(res) {
359
359
  return res.filename;
360
360
  }
361
361
  function vitePluginWeapp(ctx) {
362
- const stylesIds = /* @__PURE__ */ new Set();
363
362
  let configResolved;
364
363
  let entriesSet = /* @__PURE__ */ new Set();
365
364
  function relative(p) {
@@ -476,7 +475,7 @@ function vitePluginWeapp(ctx) {
476
475
  return source.replace(/\.wxss$/, ".css?wxss");
477
476
  }
478
477
  },
479
- load(id) {
478
+ async load(id) {
480
479
  if (entriesSet.has(id)) {
481
480
  const base = (0, import_shared3.removeExtension)(id);
482
481
  const ms = new import_magic_string.default(import_fs_extra3.default.readFileSync(id, "utf8"));
@@ -493,41 +492,33 @@ function vitePluginWeapp(ctx) {
493
492
  code: ms.toString()
494
493
  };
495
494
  } else if ((0, import_vite.isCSSRequest)(id)) {
496
- stylesIds.add(id);
497
- return {
498
- code: ""
499
- };
500
- }
501
- },
502
- async buildEnd() {
503
- const styles = {};
504
- for (const stylesId of stylesIds) {
505
- const parsed = parseRequest(stylesId);
495
+ const parsed = parseRequest(id);
506
496
  const realPath = getRealPath(parsed);
507
497
  if (await import_fs_extra3.default.exists(realPath)) {
508
498
  const css = await import_fs_extra3.default.readFile(realPath, "utf8");
509
- const res = await (0, import_vite.preprocessCSS)(css, stylesId, configResolved);
510
- const fileName = relative(normalizeCssPath(stylesId));
511
- if (styles[fileName]) {
512
- styles[fileName] += res.code;
513
- } else {
514
- styles[fileName] = res.code;
515
- }
516
- } else {
517
- stylesIds.delete(stylesId);
499
+ return {
500
+ code: css
501
+ };
518
502
  }
519
503
  }
520
- for (const style of Object.entries(styles)) {
521
- this.emitFile({
522
- type: "asset",
523
- fileName: ctx.relativeSrcRoot(style[0]),
524
- source: style[1]
525
- });
504
+ },
505
+ generateBundle(_options, bundle) {
506
+ const bundleKeys = Object.keys(bundle);
507
+ for (const bundleKey of bundleKeys) {
508
+ const asset = bundle[bundleKey];
509
+ if (bundleKey.endsWith(".css") && asset.type === "asset" && asset.originalFileName?.endsWith(".js")) {
510
+ const newFileName = normalizeCssPath(asset.originalFileName);
511
+ this.emitFile({
512
+ type: "asset",
513
+ fileName: newFileName,
514
+ source: asset.source
515
+ });
516
+ delete bundle[bundleKey];
517
+ }
526
518
  }
527
519
  }
528
- // generateBundle(_options, _bundle) {
529
- // const files = this.getWatchFiles()
530
- // console.log(files)
520
+ // writeBundle(options, bundle) {
521
+ // console.log(options, bundle)
531
522
  // },
532
523
  },
533
524
  {
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CompilerContext
3
- } from "./chunk-VXEA2S4N.mjs";
3
+ } from "./chunk-NPLMSNBG.mjs";
4
4
  import "./chunk-444MQSSG.mjs";
5
5
 
6
6
  // src/cli.ts
@@ -10,7 +10,7 @@ import { cac } from "cac";
10
10
  import { parse } from "weapp-ide-cli";
11
11
 
12
12
  // package.json
13
- var version = "1.1.3";
13
+ var version = "1.1.4";
14
14
 
15
15
  // src/constants.ts
16
16
  var VERSION = version;
package/dist/index.cjs CHANGED
@@ -359,7 +359,6 @@ function getRealPath(res) {
359
359
  return res.filename;
360
360
  }
361
361
  function vitePluginWeapp(ctx) {
362
- const stylesIds = /* @__PURE__ */ new Set();
363
362
  let configResolved;
364
363
  let entriesSet = /* @__PURE__ */ new Set();
365
364
  function relative(p) {
@@ -476,7 +475,7 @@ function vitePluginWeapp(ctx) {
476
475
  return source.replace(/\.wxss$/, ".css?wxss");
477
476
  }
478
477
  },
479
- load(id) {
478
+ async load(id) {
480
479
  if (entriesSet.has(id)) {
481
480
  const base = (0, import_shared3.removeExtension)(id);
482
481
  const ms = new import_magic_string.default(import_fs_extra3.default.readFileSync(id, "utf8"));
@@ -493,41 +492,33 @@ function vitePluginWeapp(ctx) {
493
492
  code: ms.toString()
494
493
  };
495
494
  } else if ((0, import_vite.isCSSRequest)(id)) {
496
- stylesIds.add(id);
497
- return {
498
- code: ""
499
- };
500
- }
501
- },
502
- async buildEnd() {
503
- const styles = {};
504
- for (const stylesId of stylesIds) {
505
- const parsed = parseRequest(stylesId);
495
+ const parsed = parseRequest(id);
506
496
  const realPath = getRealPath(parsed);
507
497
  if (await import_fs_extra3.default.exists(realPath)) {
508
498
  const css = await import_fs_extra3.default.readFile(realPath, "utf8");
509
- const res = await (0, import_vite.preprocessCSS)(css, stylesId, configResolved);
510
- const fileName = relative(normalizeCssPath(stylesId));
511
- if (styles[fileName]) {
512
- styles[fileName] += res.code;
513
- } else {
514
- styles[fileName] = res.code;
515
- }
516
- } else {
517
- stylesIds.delete(stylesId);
499
+ return {
500
+ code: css
501
+ };
518
502
  }
519
503
  }
520
- for (const style of Object.entries(styles)) {
521
- this.emitFile({
522
- type: "asset",
523
- fileName: ctx.relativeSrcRoot(style[0]),
524
- source: style[1]
525
- });
504
+ },
505
+ generateBundle(_options, bundle) {
506
+ const bundleKeys = Object.keys(bundle);
507
+ for (const bundleKey of bundleKeys) {
508
+ const asset = bundle[bundleKey];
509
+ if (bundleKey.endsWith(".css") && asset.type === "asset" && asset.originalFileName?.endsWith(".js")) {
510
+ const newFileName = normalizeCssPath(asset.originalFileName);
511
+ this.emitFile({
512
+ type: "asset",
513
+ fileName: newFileName,
514
+ source: asset.source
515
+ });
516
+ delete bundle[bundleKey];
517
+ }
526
518
  }
527
519
  }
528
- // generateBundle(_options, _bundle) {
529
- // const files = this.getWatchFiles()
530
- // console.log(files)
520
+ // writeBundle(options, bundle) {
521
+ // console.log(options, bundle)
531
522
  // },
532
523
  },
533
524
  {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CompilerContext
3
- } from "./chunk-VXEA2S4N.mjs";
3
+ } from "./chunk-NPLMSNBG.mjs";
4
4
  import "./chunk-444MQSSG.mjs";
5
5
  export {
6
6
  CompilerContext
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite",
3
3
  "type": "module",
4
- "version": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "description": "weapp-vite 一个现代化的小程序打包工具",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -64,9 +64,9 @@
64
64
  "pkg-types": "^1.2.0",
65
65
  "vite-tsconfig-paths": "^5.0.1",
66
66
  "@weapp-core/init": "^1.0.4",
67
+ "weapp-ide-cli": "^2.0.5",
67
68
  "@weapp-core/logger": "^1.0.1",
68
- "@weapp-core/shared": "^1.0.1",
69
- "weapp-ide-cli": "^2.0.5"
69
+ "@weapp-core/shared": "^1.0.1"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public",