weapp-vite 6.16.20 → 6.16.22

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.
@@ -1,4 +1,4 @@
1
- import { g as getRouteRuntimeGlobalKeys, i as getCompilerContext } from "./createContext-9Iyp31bM.mjs";
1
+ import { g as getRouteRuntimeGlobalKeys, i as getCompilerContext } from "./createContext-CV93nzgI.mjs";
2
2
  //#region src/auto-routes.ts
3
3
  const ROUTE_RUNTIME_OVERRIDE_KEY = Symbol.for("weapp-vite.route-runtime");
4
4
  function createGetter(resolver) {
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { C as createCjsConfigLoadError, E as isPathInside, S as parseCommentJson, T as shouldPassPlatformArgToIdeOpen, _ as createBuildScopeConfigFromCli, b as getProjectConfigFileName, f as resolveWeappViteTarget, h as resolveHmrProfileJsonPath, m as SHARED_CHUNK_VIRTUAL_PREFIX, n as syncProjectSupportFiles, p as createSharedBuildConfig, r as syncManagedTsconfigBootstrapFiles, s as formatBytes, t as createCompilerContext, v as resolveWeappConfigFile, w as getDefaultIdeProjectRoot, x as loadViteConfigFile, y as checkRuntime } from "./createContext-9Iyp31bM.mjs";
1
+ import { C as createCjsConfigLoadError, E as isPathInside, S as parseCommentJson, T as shouldPassPlatformArgToIdeOpen, _ as createBuildScopeConfigFromCli, b as getProjectConfigFileName, f as resolveWeappViteTarget, h as resolveHmrProfileJsonPath, m as SHARED_CHUNK_VIRTUAL_PREFIX, n as syncProjectSupportFiles, p as createSharedBuildConfig, r as syncManagedTsconfigBootstrapFiles, s as formatBytes, t as createCompilerContext, v as resolveWeappConfigFile, w as getDefaultIdeProjectRoot, x as loadViteConfigFile, y as checkRuntime } from "./createContext-CV93nzgI.mjs";
2
2
  import { r as logger_default, t as colors } from "./logger-mt4mSTqV.mjs";
3
- import { h as VERSION } from "./file-Dv_e5yIa.mjs";
3
+ import { h as VERSION } from "./file-CytHdoV-.mjs";
4
4
  import { o as resolveWeappMcpConfig, s as startWeappViteMcpServer } from "./mcp-qmDOTH07.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import path, { posix } from "pathe";
@@ -3708,7 +3708,7 @@ function resolveRunnableHotkeyDefinition(input) {
3708
3708
  }
3709
3709
  //#endregion
3710
3710
  //#region package.json
3711
- var version = "6.16.20";
3711
+ var version = "6.16.22";
3712
3712
  //#endregion
3713
3713
  //#region src/cli/devHotkeys/format.ts
3714
3714
  const FULLWIDTH_ASCII_START = 65281;
@@ -1,6 +1,6 @@
1
1
  import { n as applyWeappViteHostMeta } from "./pluginHost--CaeyWpA.mjs";
2
2
  import { n as configureLogger, r as logger_default } from "./logger-mt4mSTqV.mjs";
3
- import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as supportedCssLangs, y as templateExtensions } from "./file-Dv_e5yIa.mjs";
3
+ import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as supportedCssLangs, y as templateExtensions } from "./file-CytHdoV-.mjs";
4
4
  import { createRequire, isBuiltin } from "node:module";
5
5
  import path, { posix } from "pathe";
6
6
  import path$1, { normalize, relative, win32 } from "node:path";
@@ -17041,9 +17041,32 @@ function injectSharedStyleImports(css, modulePath, fileName, sharedStyles, confi
17041
17041
  //#endregion
17042
17042
  //#region src/plugins/css.ts
17043
17043
  const LEADING_BLANK_LINES_RE = /^(?:[ \t]*\r?\n)+/;
17044
+ const SOURCE_STYLE_ASSET_RE = /\.(?:wxss|css|less|sass|scss|styl|stylus|pcss|postcss|sss)$/;
17045
+ const VITE_PREPROCESS_STYLE_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss)$/;
17044
17046
  function stripLeadingBlankLines(code) {
17045
17047
  return code.replace(LEADING_BLANK_LINES_RE, "");
17046
17048
  }
17049
+ function isSourceStyleAsset(fileName) {
17050
+ return SOURCE_STYLE_ASSET_RE.test(fileName);
17051
+ }
17052
+ function shouldPreprocessWithVite(fileName) {
17053
+ return VITE_PREPROCESS_STYLE_RE.test(fileName);
17054
+ }
17055
+ async function preprocessStyleSource(code, fileName, resolvedConfig, options) {
17056
+ const normalizedCss = stripLeadingBlankLines(code);
17057
+ if (!resolvedConfig || options?.enabled === false || !shouldPreprocessWithVite(fileName)) return {
17058
+ css: normalizedCss,
17059
+ dependencies: []
17060
+ };
17061
+ const processed = await preprocessCSS(normalizedCss, fileName, resolvedConfig);
17062
+ return {
17063
+ css: stripLeadingBlankLines(processed.code),
17064
+ dependencies: processed.deps ? Array.from(processed.deps) : []
17065
+ };
17066
+ }
17067
+ function resolveOutputStyleFileName(configService, stylePath) {
17068
+ return configService.relativeOutputPath(changeFileExtension(stylePath, configService.outputExtensions.wxss));
17069
+ }
17047
17070
  function emitCssAssetIfChanged(ctx, pluginCtx, bundle, fileName, source) {
17048
17071
  const normalizedFileName = toPosixPath(fileName);
17049
17072
  const cache = ctx.runtimeState?.css.emittedSource;
@@ -17062,13 +17085,15 @@ function emitCssAssetIfChanged(ctx, pluginCtx, bundle, fileName, source) {
17062
17085
  cache?.set(normalizedFileName, source);
17063
17086
  return true;
17064
17087
  }
17065
- async function emitStyleSidecarAsset(ctx, pluginCtx, bundle, stylePath) {
17088
+ async function emitStyleSidecarAsset(ctx, pluginCtx, bundle, stylePath, resolvedConfig) {
17066
17089
  const { configService } = ctx;
17067
- const fileName = configService.relativeOutputPath(stylePath);
17090
+ const fileName = resolveOutputStyleFileName(configService, stylePath);
17068
17091
  if (!fileName) return false;
17069
- return emitCssAssetIfChanged(ctx, pluginCtx, bundle, fileName, injectSharedStyleImports(await processCssWithCache(stripLeadingBlankLines(await fs.readFile(stylePath, "utf8")), configService), stylePath, fileName, collectSharedStyleEntries(ctx, configService), configService));
17092
+ const { css, dependencies } = await preprocessStyleSource(await fs.readFile(stylePath, "utf8"), stylePath, resolvedConfig);
17093
+ if (typeof pluginCtx.addWatchFile === "function") for (const dependency of dependencies) pluginCtx.addWatchFile(normalizeWatchPath(dependency));
17094
+ return emitCssAssetIfChanged(ctx, pluginCtx, bundle, fileName, injectSharedStyleImports(await processCssWithCache(css, configService), stylePath, fileName, collectSharedStyleEntries(ctx, configService), configService));
17070
17095
  }
17071
- async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, sharedStyles, emitted) {
17096
+ async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, sharedStyles, emitted, resolvedConfig) {
17072
17097
  if (asset.type !== "asset") return;
17073
17098
  const toAbsolute = (id) => {
17074
17099
  return toAbsoluteId(id, configService, void 0, { base: "cwd" }) || id;
@@ -17086,36 +17111,55 @@ async function handleBundleEntry(ctx, bundle, bundleKey, asset, configService, s
17086
17111
  }
17087
17112
  return owners;
17088
17113
  };
17089
- if (bundleKey.endsWith(".wxss")) {
17114
+ const resolveOriginalStylePath = () => {
17090
17115
  const [rawOriginal] = asset.originalFileNames ?? [];
17091
- const absOriginal = rawOriginal ? toAbsolute(rawOriginal) : path.resolve(configService.absoluteSrcRoot, bundleKey);
17092
- const fileName = configService.relativeOutputPath(absOriginal);
17116
+ return rawOriginal ? toAbsolute(rawOriginal) : path.resolve(configService.absoluteSrcRoot, bundleKey);
17117
+ };
17118
+ const emitStyleAssetForOwner = async (owner, preprocessId, shouldPreprocess) => {
17119
+ const fileName = resolveOutputStyleFileName(configService, owner);
17120
+ if (!fileName) return;
17121
+ const normalizedFileName = toPosixPath(fileName);
17122
+ const { css, dependencies } = await preprocessStyleSource(asset.source.toString(), preprocessId, resolvedConfig, { enabled: shouldPreprocess });
17123
+ if (typeof this.addWatchFile === "function") for (const dependency of dependencies) this.addWatchFile(normalizeWatchPath(dependency));
17124
+ const cssWithImports = injectSharedStyleImports(await processCssWithCache(css, configService), owner, fileName, sharedStyles, configService);
17125
+ emitCssAssetIfChanged(ctx, this, bundle, fileName, cssWithImports);
17126
+ emitted.add(normalizedFileName);
17127
+ };
17128
+ const isFinalStyleAsset = bundleKey.endsWith(`.${configService.outputExtensions.wxss}`);
17129
+ const isCssAsset = bundleKey.endsWith(".css");
17130
+ const isSourceStyleAssetKey = isSourceStyleAsset(bundleKey);
17131
+ if (isFinalStyleAsset) {
17132
+ const absOriginal = resolveOriginalStylePath();
17133
+ const fileName = resolveOutputStyleFileName(configService, absOriginal);
17093
17134
  if (fileName) emitted.add(toPosixPath(fileName));
17094
- if (fileName && fileName !== bundleKey) {
17095
- delete bundle[bundleKey];
17096
- const css = await fs.readFile(absOriginal, "utf8");
17097
- emitCssAssetIfChanged(ctx, this, bundle, fileName, css);
17135
+ if (fileName) {
17136
+ const source = asset.source.toString();
17137
+ const { css, dependencies } = await preprocessStyleSource(source, absOriginal, resolvedConfig, { enabled: shouldPreprocessWithVite(absOriginal) });
17138
+ if (typeof this.addWatchFile === "function") for (const dependency of dependencies) this.addWatchFile(normalizeWatchPath(dependency));
17139
+ const processedCss = await processCssWithCache(css, configService);
17140
+ if (fileName !== bundleKey) {
17141
+ delete bundle[bundleKey];
17142
+ emitCssAssetIfChanged(ctx, this, bundle, fileName, processedCss);
17143
+ } else if (processedCss !== source) asset.source = processedCss;
17098
17144
  }
17099
17145
  return;
17100
17146
  }
17101
- if (!bundleKey.endsWith(".css")) return;
17147
+ if (!isCssAsset && !isSourceStyleAssetKey) return;
17102
17148
  const ownersFromChunks = collectCssOwnersFromChunks();
17103
17149
  const owners = ownersFromChunks.size ? ownersFromChunks : new Set((asset.originalFileNames ?? []).map(normalizeOwnerId).filter((originalFileName) => {
17104
17150
  return isJsOrTs(originalFileName) || originalFileName.endsWith(".vue");
17105
17151
  }).map(toAbsolute));
17106
17152
  if (!owners.size) {
17153
+ if (isSourceStyleAssetKey && !isCssAsset) {
17154
+ await emitStyleAssetForOwner(resolveOriginalStylePath(), resolveOriginalStylePath(), !isCssAsset);
17155
+ delete bundle[bundleKey];
17156
+ return;
17157
+ }
17107
17158
  delete bundle[bundleKey];
17108
17159
  return;
17109
17160
  }
17110
17161
  await Promise.all(Array.from(owners).map(async (owner) => {
17111
- const modulePath = owner;
17112
- const converted = changeFileExtension(modulePath, configService.outputExtensions.wxss);
17113
- const fileName = configService.relativeOutputPath(converted);
17114
- if (!fileName) return;
17115
- const normalizedFileName = toPosixPath(fileName);
17116
- const cssWithImports = injectSharedStyleImports(await processCssWithCache(stripLeadingBlankLines(asset.source.toString()), configService), modulePath, fileName, sharedStyles, configService);
17117
- emitCssAssetIfChanged(ctx, this, bundle, fileName, cssWithImports);
17118
- emitted.add(normalizedFileName);
17162
+ await emitStyleAssetForOwner(owner, resolveOriginalStylePath(), !isCssAsset);
17119
17163
  }));
17120
17164
  delete bundle[bundleKey];
17121
17165
  }
@@ -17161,7 +17205,7 @@ async function generateBundleSharedCss(ctx, configService, bundle, resolvedConfi
17161
17205
  const sharedStyles = collectSharedStyleEntries(ctx, configService);
17162
17206
  const emitted = /* @__PURE__ */ new Set();
17163
17207
  const tasks = Object.entries(bundle).map(([bundleKey, asset]) => {
17164
- return handleBundleEntry.call(this, ctx, bundle, bundleKey, asset, configService, sharedStyles, emitted);
17208
+ return handleBundleEntry.call(this, ctx, bundle, bundleKey, asset, configService, sharedStyles, emitted, resolvedConfig);
17165
17209
  });
17166
17210
  await Promise.all(tasks);
17167
17211
  await emitSharedStyleEntries.call(this, ctx, sharedStyles, emitted, configService, bundle, resolvedConfig);
@@ -18919,7 +18963,7 @@ function createRenderStartHook(state) {
18919
18963
  return async function renderStart() {
18920
18964
  if (isCurrentStyleSidecarUpdate(state)) {
18921
18965
  const currentFile = ctx.runtimeState.build.hmr.profile.file;
18922
- if (typeof currentFile === "string" && path.extname(currentFile)) await emitStyleSidecarAsset(ctx, this, {}, currentFile);
18966
+ if (typeof currentFile === "string" && path.extname(currentFile)) await emitStyleSidecarAsset(ctx, this, {}, currentFile, state.resolvedConfig);
18923
18967
  }
18924
18968
  emitJsonAssets.call(this, state);
18925
18969
  state.watchFilesSnapshot = emitWxmlAssetsWithCache({
@@ -20061,6 +20105,9 @@ function createCoreLifecyclePlugin(state) {
20061
20105
  return {
20062
20106
  name: "weapp-vite:pre",
20063
20107
  enforce: "pre",
20108
+ configResolved(config) {
20109
+ state.resolvedConfig = config;
20110
+ },
20064
20111
  buildStart: createBuildStartHook(state),
20065
20112
  watchChange: createWatchChangeHook(state),
20066
20113
  options: createOptionsHook(state),
@@ -24101,7 +24148,7 @@ async function loadAppEntry(ctx, scanState) {
24101
24148
  const vueAppPath = await findVueEntry(appBasename);
24102
24149
  let configFromVue;
24103
24150
  if (!appConfigFile && vueAppPath) {
24104
- const { extractConfigFromVue } = await import("./file-IuX99F00.mjs");
24151
+ const { extractConfigFromVue } = await import("./file-O6w4ipMR.mjs");
24105
24152
  configFromVue = await extractConfigFromVue(vueAppPath);
24106
24153
  if (configFromVue) appConfigFile = vueAppPath;
24107
24154
  }
@@ -84,7 +84,7 @@ function resolveAutoRoutesMacroImportPath() {
84
84
  }
85
85
  async function resolveAutoRoutesInlineSnapshot() {
86
86
  try {
87
- const { getCompilerContext } = await import("./getInstance-DS0CkWYU.mjs");
87
+ const { getCompilerContext } = await import("./getInstance-LxnEzp6v.mjs");
88
88
  const compilerContext = getCompilerContext();
89
89
  const service = compilerContext.autoRoutesService;
90
90
  const reference = service?.getReference?.();
@@ -0,0 +1,2 @@
1
+ import { t as extractConfigFromVue } from "./file-CytHdoV-.mjs";
2
+ export { extractConfigFromVue };
@@ -0,0 +1,2 @@
1
+ import { i as getCompilerContext } from "./createContext-CV93nzgI.mjs";
2
+ export { getCompilerContext };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as defineThemeJson, i as defineSitemapJson, n as defineComponentJson, r as definePageJson, t as defineAppJson } from "./json-BL8Dhhk6.mjs";
2
2
  import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost--CaeyWpA.mjs";
3
3
  import { t as defineConfig } from "./config-DRGcCi3h.mjs";
4
- import { c as WEB_PLATFORM_ALIASES, d as isWebPlatform, f as resolveWeappViteTarget, l as getSupportedWeappVitePlatforms, t as createCompilerContext, u as getSupportedWeappViteTargetDescriptors } from "./createContext-9Iyp31bM.mjs";
4
+ import { c as WEB_PLATFORM_ALIASES, d as isWebPlatform, f as resolveWeappViteTarget, l as getSupportedWeappVitePlatforms, t as createCompilerContext, u as getSupportedWeappViteTargetDescriptors } from "./createContext-CV93nzgI.mjs";
5
5
  import { i as createWevuComponent, n as defineProps, r as setPageLayout, t as defineEmits } from "./runtime-C3z9pDQB.mjs";
6
6
  export { WEAPP_VITE_HOST_NAME, WEB_PLATFORM_ALIASES, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, getSupportedWeappVitePlatforms, getSupportedWeappViteTargetDescriptors, isWeappViteHost, isWebPlatform, resolveWeappViteHostMeta, resolveWeappViteTarget, setPageLayout };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite",
3
3
  "type": "module",
4
- "version": "6.16.20",
4
+ "version": "6.16.22",
5
5
  "description": "weapp-vite 一个现代化的小程序打包工具",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -117,22 +117,22 @@
117
117
  "vite-tsconfig-paths": "^6.1.1",
118
118
  "vue": "^3.5.34",
119
119
  "vue-tsc": "^3.3.1",
120
- "@weapp-core/constants": "0.1.8",
120
+ "@weapp-core/constants": "0.1.9",
121
121
  "@weapp-core/init": "6.0.9",
122
122
  "@weapp-core/logger": "3.1.1",
123
123
  "@weapp-core/schematics": "6.0.4",
124
124
  "@weapp-core/shared": "3.0.4",
125
- "@weapp-vite/ast": "6.16.20",
126
- "@weapp-vite/mcp": "1.3.4",
127
- "@weapp-vite/miniprogram-automator": "1.1.1",
125
+ "@weapp-vite/ast": "6.16.22",
126
+ "@weapp-vite/mcp": "1.3.6",
127
+ "@weapp-vite/miniprogram-automator": "1.1.3",
128
128
  "@weapp-vite/volar": "2.1.0",
129
- "@weapp-vite/web": "1.3.24",
129
+ "@weapp-vite/web": "1.3.25",
130
130
  "@wevu/api": "0.2.9",
131
- "@wevu/web-apis": "1.2.15",
131
+ "@wevu/web-apis": "1.2.16",
132
132
  "rolldown-require": "2.0.17",
133
133
  "vite-plugin-performance": "2.0.1",
134
- "weapp-ide-cli": "5.3.0",
135
- "wevu": "6.16.20"
134
+ "weapp-ide-cli": "5.3.2",
135
+ "wevu": "6.16.22"
136
136
  },
137
137
  "publishConfig": {
138
138
  "access": "public",
@@ -1,2 +0,0 @@
1
- import { t as extractConfigFromVue } from "./file-Dv_e5yIa.mjs";
2
- export { extractConfigFromVue };
@@ -1,2 +0,0 @@
1
- import { i as getCompilerContext } from "./createContext-9Iyp31bM.mjs";
2
- export { getCompilerContext };