@vureact/compiler-core 1.0.4 → 1.1.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.
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9;/**
2
- * @vureact/compiler-core v1.0.3
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;/**
2
+ * @vureact/compiler-core v1.1.1
3
3
  * (c) 2025-present Ruihong Zhong (Ryan John)
4
4
  * @license MIT
5
5
  */
@@ -1401,14 +1401,18 @@ var _less = require('less'); var _less2 = _interopRequireDefault(_less);
1401
1401
  var _sass = require('sass'); var sass = _interopRequireWildcard(_sass);
1402
1402
  function resolveLessSass(source, options) {
1403
1403
  const { lang, enabled, filename } = options;
1404
- if (!enabled) return source;
1405
- if (lang === "less") {
1406
- return resolveLessSync(source, filename);
1404
+ const result = { code: source, fileExt: ".css" };
1405
+ if (!options.enabled) {
1406
+ result.fileExt = `.${options.lang}`;
1407
1407
  }
1408
- if (lang === "scss" || lang === "sass") {
1409
- return resolveSassSync(source, filename);
1408
+ if (!enabled) return result;
1409
+ if (lang === "less") {
1410
+ result.code = resolveLessSync(source, filename);
1411
+ } else if (lang === "scss" || lang === "sass") {
1412
+ result.code = resolveSassSync(source, filename);
1410
1413
  }
1411
- return source;
1414
+ result.code = resolveImportExtensions(result.code);
1415
+ return result;
1412
1416
  }
1413
1417
  function resolveLessSync(source, filename) {
1414
1418
  let result = "";
@@ -1459,6 +1463,12 @@ function resolveSassSync(source, filename) {
1459
1463
  const result = sass.compileString(source, options);
1460
1464
  return result.css;
1461
1465
  }
1466
+ function resolveImportExtensions(code) {
1467
+ if (code.includes(".less") || code.includes(".scss") || code.includes(".sass")) {
1468
+ return code.replaceAll(/\.(less|scss|sass)(?=['")])/g, ".css");
1469
+ }
1470
+ return code;
1471
+ }
1462
1472
 
1463
1473
  // src/core/parse/sfc/process/resolve-styles.ts
1464
1474
  function resolveStyles(descriptor, ctx, result) {
@@ -1478,13 +1488,12 @@ function resolveStyles(descriptor, ctx, result) {
1478
1488
  { file: filename }
1479
1489
  );
1480
1490
  }
1481
- const source = resolveLessSass(content, {
1491
+ const { code, fileExt } = resolveLessSass(content, {
1482
1492
  lang,
1483
1493
  filename,
1484
1494
  enabled: preprocessStyles
1485
1495
  });
1486
- const disablePreprocessing = lang !== "css" && !preprocessStyles;
1487
- let ext = disablePreprocessing ? `.${lang}` : ".css";
1496
+ let ext = fileExt;
1488
1497
  if (style.module) {
1489
1498
  ext = `-${fileId}.module${ext}`;
1490
1499
  styleData.moduleName = typeof style.module === "boolean" ? STYLE_MODULE_NAME : style.module;
@@ -1492,18 +1501,18 @@ function resolveStyles(descriptor, ctx, result) {
1492
1501
  ext = `-${fileId}${ext}`;
1493
1502
  }
1494
1503
  if (style.scoped) {
1495
- if (disablePreprocessing) {
1504
+ if (lang !== "css" && !preprocessStyles) {
1496
1505
  logger.warn(
1497
1506
  "Scoped styles are only supported for CSS. Preprocessing is disabled, so scoped styles will not be applied.",
1498
1507
  { file: filename }
1499
1508
  );
1500
1509
  return;
1501
1510
  }
1502
- const result2 = processScopedWithPostCss(source, fileId);
1511
+ const result2 = processScopedWithPostCss(code, fileId);
1503
1512
  style.content = result2.css.trim();
1504
1513
  styleData.scopeId = result2.scopeId;
1505
1514
  } else {
1506
- style.content = source;
1515
+ style.content = code;
1507
1516
  }
1508
1517
  const filePath = filename.replace(/\.vue$/i, ext);
1509
1518
  styleData.filePath = filePath;
@@ -1591,7 +1600,8 @@ function parse(source, ctx, options) {
1591
1600
  // src/core/transform/sfc/script/syntax-processor/postprocess/insert-css-import.ts
1592
1601
 
1593
1602
  function insertCSSImport(ctx) {
1594
- if (ctx.inputType !== "sfc") return;
1603
+ const { inputType } = ctx;
1604
+ if (inputType !== "sfc") return;
1595
1605
  const { filePath, moduleName } = ctx.styleData;
1596
1606
  if (!filePath) return;
1597
1607
  const scriptIR = getScriptIR(ctx);
@@ -1634,6 +1644,44 @@ function insertRequiredImports(ctx) {
1634
1644
  const processedModules = /* @__PURE__ */ new Set();
1635
1645
  let hasProcessedImports = false;
1636
1646
  recordImport(ctx, PACKAGE_NAME.react, REACT_API_MAP.memo);
1647
+ function resolveRequiredImport(path7) {
1648
+ const { node } = path7;
1649
+ const moduleName = node.source.value.toLowerCase();
1650
+ const isVueLike = isVueEcosystemPackage(moduleName);
1651
+ mergeImports(node, ctx);
1652
+ if (processedModules.has(moduleName) && !path7.removed) {
1653
+ path7.remove();
1654
+ return;
1655
+ }
1656
+ processedModules.add(moduleName);
1657
+ if (!hasProcessedImports) {
1658
+ const required = createRequiredImports(ctx);
1659
+ if (isVueLike) {
1660
+ path7.replaceWithMultiple(required);
1661
+ } else if (moduleName === PACKAGE_NAME.react) {
1662
+ path7.insertAfter(required);
1663
+ } else {
1664
+ path7.insertBefore(required);
1665
+ }
1666
+ hasProcessedImports = true;
1667
+ }
1668
+ if (isVueLike && !path7.removed) {
1669
+ path7.remove();
1670
+ return;
1671
+ }
1672
+ replaceVueSuffix(ctx, node.source);
1673
+ }
1674
+ function resolveStyleFileExt(path7) {
1675
+ if (!ctx.preprocessStyles) return;
1676
+ const { node } = path7;
1677
+ if (!node || !node.source || !node.source.value) return;
1678
+ const importSource = node.source.value;
1679
+ if (typeof importSource !== "string") return;
1680
+ const styleExtRegex = /\.(less|sass|scss)$/i;
1681
+ if (!styleExtRegex.test(importSource)) return;
1682
+ const newSource = importSource.replace(styleExtRegex, ".css");
1683
+ node.source.value = newSource;
1684
+ }
1637
1685
  return {
1638
1686
  // 增加 Program.exit 兜底注入 required imports(处理无 ImportDeclaration 的 SFC)
1639
1687
  Program: {
@@ -1645,31 +1693,8 @@ function insertRequiredImports(ctx) {
1645
1693
  }
1646
1694
  },
1647
1695
  ImportDeclaration(path7) {
1648
- const { node } = path7;
1649
- const moduleName = node.source.value.toLowerCase();
1650
- const isVueLike = isVueEcosystemPackage(moduleName);
1651
- mergeImports(node, ctx);
1652
- if (processedModules.has(moduleName) && !path7.removed) {
1653
- path7.remove();
1654
- return;
1655
- }
1656
- processedModules.add(moduleName);
1657
- if (!hasProcessedImports) {
1658
- const required = createRequiredImports(ctx);
1659
- if (isVueLike) {
1660
- path7.replaceWithMultiple(required);
1661
- } else if (moduleName === PACKAGE_NAME.react) {
1662
- path7.insertAfter(required);
1663
- } else {
1664
- path7.insertBefore(required);
1665
- }
1666
- hasProcessedImports = true;
1667
- }
1668
- if (isVueLike && !path7.removed) {
1669
- path7.remove();
1670
- return;
1671
- }
1672
- replaceVueSuffix(ctx, node.source);
1696
+ resolveRequiredImport(path7);
1697
+ resolveStyleFileExt(path7);
1673
1698
  }
1674
1699
  };
1675
1700
  }
@@ -5076,7 +5101,7 @@ function transform(ast, ctx, options) {
5076
5101
  }
5077
5102
 
5078
5103
  // package.json
5079
- var version = "1.0.3";
5104
+ var version = "1.1.1";
5080
5105
  var bin = {
5081
5106
  vureact: "./bin/vureact.js"
5082
5107
  };
@@ -5085,6 +5110,7 @@ var bin = {
5085
5110
  var CacheKey = /* @__PURE__ */ ((CacheKey2) => {
5086
5111
  CacheKey2["SFC"] = "sfc";
5087
5112
  CacheKey2["SCRIPT"] = "script";
5113
+ CacheKey2["STYLE"] = "style";
5088
5114
  CacheKey2["ASSET"] = "copied";
5089
5115
  return CacheKey2;
5090
5116
  })(CacheKey || {});
@@ -5190,6 +5216,7 @@ var Helper = (_class3 = class {
5190
5216
  "package-lock.json",
5191
5217
  "pnpm-lock.yaml",
5192
5218
  "index.html",
5219
+ "yarn-lock.",
5193
5220
  "tsconfig.",
5194
5221
  "vite.config.",
5195
5222
  "eslint.config.",
@@ -5325,6 +5352,7 @@ var Helper = (_class3 = class {
5325
5352
  source: {
5326
5353
  ["sfc" /* SFC */]: [],
5327
5354
  ["script" /* SCRIPT */]: [],
5355
+ ["style" /* STYLE */]: [],
5328
5356
  ["copied" /* ASSET */]: []
5329
5357
  }
5330
5358
  };
@@ -5465,6 +5493,39 @@ var Helper = (_class3 = class {
5465
5493
  }
5466
5494
  }, _class3);
5467
5495
 
5496
+ // src/core/parse/style-only.ts
5497
+ function parseOnlyStyle(source, ctx, options) {
5498
+ const { filename } = ctx;
5499
+ let lang = filename.split(".").pop();
5500
+ if (!lang) {
5501
+ lang = "css";
5502
+ logger.warn(`The style file without an extension has been fallback to .css`, {
5503
+ file: filename
5504
+ });
5505
+ }
5506
+ const { code, fileExt } = resolveLessSass(source, {
5507
+ filename,
5508
+ lang,
5509
+ enabled: ctx.preprocessStyles
5510
+ });
5511
+ const result = {
5512
+ template: null,
5513
+ script: null,
5514
+ style: {
5515
+ source: {
5516
+ type: "style",
5517
+ content: code,
5518
+ lang: fileExt.replace(".", ""),
5519
+ attrs: {},
5520
+ loc: {}
5521
+ },
5522
+ ast: void 0
5523
+ }
5524
+ };
5525
+ executePlugins(_optionalChain([options, 'optionalAccess', _199 => _199.plugins]), result, ctx);
5526
+ return result;
5527
+ }
5528
+
5468
5529
  // src/compiler/context/adapter.ts
5469
5530
 
5470
5531
 
@@ -5526,19 +5587,42 @@ var CompilationAdapter = class _CompilationAdapter {
5526
5587
  static createContext(input) {
5527
5588
  const ctx = createCompilationCtx();
5528
5589
  const inputType = _CompilationAdapter.detectInputType(input.filename);
5529
- if (inputType.startsWith("script-")) {
5530
- ctx.data.inputType = inputType;
5590
+ const initTemplateData = () => {
5531
5591
  ctx.data.templateData = {};
5592
+ };
5593
+ const initScriptData = () => {
5594
+ ctx.data.scriptData = {};
5595
+ };
5596
+ const initStyleData = () => {
5532
5597
  ctx.data.styleData = {};
5598
+ };
5599
+ if (inputType.startsWith("script-")) {
5600
+ initTemplateData();
5601
+ initStyleData();
5602
+ } else if (inputType === "style") {
5603
+ initTemplateData();
5604
+ initScriptData();
5533
5605
  }
5534
5606
  ctx.init({ inputType, ...input });
5535
5607
  return ctx;
5536
5608
  }
5537
5609
  static detectInputType(filename) {
5538
- const ext = _path2.default.extname(filename);
5539
- if (ext === ".vue") return "sfc";
5540
- if (ext === ".ts") return "script-ts";
5541
- return "script-js";
5610
+ const ext = _path2.default.extname(filename).toLowerCase();
5611
+ switch (ext) {
5612
+ case ".vue":
5613
+ return "sfc";
5614
+ case ".js":
5615
+ return "script-js";
5616
+ case ".ts":
5617
+ return "script-ts";
5618
+ case ".css":
5619
+ case ".less":
5620
+ case ".sass":
5621
+ case ".scss":
5622
+ return "style";
5623
+ default:
5624
+ return "unknow";
5625
+ }
5542
5626
  }
5543
5627
  };
5544
5628
 
@@ -5597,8 +5681,7 @@ var BaseCompiler = (_class5 = class extends Helper {
5597
5681
  * `;
5598
5682
  *
5599
5683
  * const result = compiler.compile(vueCode, 'MyComponent.vue');
5600
- * console.log(result.code); // 生成的 React JSX 代码
5601
- * console.log(result.fileInfo.jsx.file); // 输出文件路径
5684
+ * console.log(result);
5602
5685
  * ```
5603
5686
  *
5604
5687
  * @throws 不会直接抛出异常,错误通过日志系统记录
@@ -5610,21 +5693,29 @@ var BaseCompiler = (_class5 = class extends Helper {
5610
5693
  compile(source, filename) {
5611
5694
  const { plugins, preprocessStyles = true } = this.options;
5612
5695
  const fileId = this.genHash(filename);
5613
- const genOptions = this.prepareGenerateOptions(filename);
5614
5696
  const ctx = this.createContext({
5615
5697
  fileId,
5616
5698
  filename,
5617
5699
  source,
5618
5700
  preprocessStyles
5619
5701
  });
5620
- try {
5621
- const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _199 => _199.parser]) });
5622
- const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _200 => _200.transformer]) });
5702
+ const genOptions = this.prepareGenerateOptions(filename);
5703
+ const resolveSFCAndScriptFile = () => {
5704
+ const ast = parse(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _200 => _200.parser]) });
5705
+ const ir = transform(ast, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _201 => _201.transformer]) });
5623
5706
  const gen = generate(ir, ctx.data, {
5624
5707
  ...genOptions,
5625
- plugins: _optionalChain([plugins, 'optionalAccess', _201 => _201.codegen])
5708
+ plugins: _optionalChain([plugins, 'optionalAccess', _202 => _202.codegen])
5626
5709
  });
5627
- const result = this.resolveResult(ir, gen, ctx.data);
5710
+ return this.resolveMainResult(ir, gen, ctx.data);
5711
+ };
5712
+ const resolveStyleFile = () => {
5713
+ const result = parseOnlyStyle(source, ctx.data, { plugins: _optionalChain([plugins, 'optionalAccess', _203 => _203.parser]) });
5714
+ return this.resolveStyleResult(result, ctx.data);
5715
+ };
5716
+ try {
5717
+ const isStyleFile = ctx.data.inputType === "style";
5718
+ const result = isStyleFile ? resolveStyleFile() : resolveSFCAndScriptFile();
5628
5719
  if (plugins) {
5629
5720
  const { parser, transformer, codegen, ...rest } = plugins;
5630
5721
  executePlugins(rest, result, ctx);
@@ -5634,67 +5725,6 @@ var BaseCompiler = (_class5 = class extends Helper {
5634
5725
  ctx.clear();
5635
5726
  }
5636
5727
  }
5637
- /**
5638
- * 处理 SFC 和 Script 文件的编译结果
5639
- *
5640
- * 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
5641
- * 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
5642
- * 对于 Script 文件,返回仅包含脚本信息的结果。
5643
- *
5644
- * 关键处理逻辑:
5645
- * 1. 构建基础结果:包含文件ID、路由信息和生成的代码
5646
- * 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
5647
- * 3. 区分文件类型:
5648
- * - SFC 文件:生成 .tsx 扩展名,包含样式信息
5649
- * - Script 文件:保持原扩展名,不包含样式信息
5650
- * 4. 样式处理:提取样式文件路径、作用域ID和样式代码
5651
- *
5652
- * @private
5653
- * @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
5654
- * @param gen - 代码生成结果,包含生成的代码和源码映射
5655
- * @param ctxData - 编译上下文数据,包含文件信息和编译状态
5656
- * @returns {CompilationResult} 整理后的编译结果
5657
- *
5658
- * @remarks
5659
- * - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
5660
- * - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
5661
- * - 路由检测:自动检测组件是否使用路由,用于依赖注入
5662
- * - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
5663
- *
5664
- * @see {@link SFCCompilationResult} SFC 编译结果类型
5665
- * @see {@link ScriptCompilationResult} Script 编译结果类型
5666
- */
5667
- resolveResult(ir, gen, ctxData) {
5668
- const { fileId, filename, scriptData, styleData } = ctxData;
5669
- const base = {
5670
- fileId,
5671
- hasRoute: ctxData.route,
5672
- ...gen
5673
- };
5674
- const { lang } = scriptData;
5675
- const file = this.resolveOutputPath(filename, lang);
5676
- if (ctxData.inputType === "sfc") {
5677
- return {
5678
- fileInfo: {
5679
- jsx: {
5680
- file: `${file}x`,
5681
- // 'xxx.ts' + 'x' => 'xxx.tsx'
5682
- lang
5683
- },
5684
- css: {
5685
- file: _optionalChain([styleData, 'optionalAccess', _202 => _202.filePath]),
5686
- hash: _optionalChain([styleData, 'optionalAccess', _203 => _203.scopeId]),
5687
- code: _optionalChain([ir, 'optionalAccess', _204 => _204.style])
5688
- }
5689
- },
5690
- ...base
5691
- };
5692
- }
5693
- return {
5694
- fileInfo: { script: { file, lang } },
5695
- ...base
5696
- };
5697
- }
5698
5728
  /**
5699
5729
  * 初始化 Babel 代码生成选项
5700
5730
  *
@@ -5759,6 +5789,87 @@ var BaseCompiler = (_class5 = class extends Helper {
5759
5789
  }
5760
5790
  return mergedOptions;
5761
5791
  }
5792
+ /**
5793
+ * 处理 SFC 和 Script 文件的编译结果
5794
+ *
5795
+ * 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
5796
+ * 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
5797
+ * 对于 Script 文件,返回仅包含脚本信息的结果。
5798
+ *
5799
+ * 关键处理逻辑:
5800
+ * 1. 构建基础结果:包含文件ID、路由信息和生成的代码
5801
+ * 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
5802
+ * 3. 区分文件类型:
5803
+ * - SFC 文件:生成 .tsx 扩展名,包含样式信息
5804
+ * - Script 文件:保持原扩展名,不包含样式信息
5805
+ * 4. 样式处理:提取样式文件路径、作用域ID和样式代码
5806
+ *
5807
+ * @private
5808
+ * @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
5809
+ * @param gen - 代码生成结果,包含生成的代码和源码映射
5810
+ * @param ctxData - 编译上下文数据,包含文件信息和编译状态
5811
+ * @returns {CompilationResult} 整理后的编译结果
5812
+ *
5813
+ * @remarks
5814
+ * - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
5815
+ * - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
5816
+ * - 路由检测:自动检测组件是否使用路由,用于依赖注入
5817
+ * - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
5818
+ *
5819
+ * @see {@link SFCCompilationResult} SFC 编译结果类型
5820
+ * @see {@link ScriptCompilationResult} Script 编译结果类型
5821
+ */
5822
+ resolveMainResult(ir, gen, ctxData) {
5823
+ const { fileId, filename, scriptData, styleData, inputType } = ctxData;
5824
+ const base = {
5825
+ fileId,
5826
+ hasRoute: ctxData.route,
5827
+ ...gen
5828
+ };
5829
+ const { lang } = scriptData;
5830
+ const file = this.resolveOutputPath(filename, lang);
5831
+ if (inputType === "sfc") {
5832
+ return {
5833
+ fileInfo: {
5834
+ jsx: {
5835
+ file: `${file}x`,
5836
+ // 'xxx.ts' + 'x' => 'xxx.tsx'
5837
+ lang
5838
+ },
5839
+ css: {
5840
+ file: _optionalChain([styleData, 'optionalAccess', _204 => _204.filePath]),
5841
+ hash: _optionalChain([styleData, 'optionalAccess', _205 => _205.scopeId]),
5842
+ code: _optionalChain([ir, 'optionalAccess', _206 => _206.style])
5843
+ }
5844
+ },
5845
+ ...base
5846
+ };
5847
+ }
5848
+ return {
5849
+ fileInfo: { script: { file, lang } },
5850
+ ...base
5851
+ };
5852
+ }
5853
+ /**
5854
+ * 处理 Style 文件的编译结果
5855
+ * @param data style 文件解析结果
5856
+ * @param ctxData 上下文数据
5857
+ */
5858
+ resolveStyleResult(data, ctxData) {
5859
+ const { fileId, filename } = ctxData;
5860
+ const { lang, content = "" } = data.style.source;
5861
+ const file = this.resolveOutputPath(filename, lang);
5862
+ return {
5863
+ fileId,
5864
+ fileInfo: {
5865
+ style: {
5866
+ file,
5867
+ lang
5868
+ }
5869
+ },
5870
+ code: content
5871
+ };
5872
+ }
5762
5873
  }, _class5);
5763
5874
 
5764
5875
  // src/utils/calc-elapsed-time.ts
@@ -5783,11 +5894,13 @@ var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
5783
5894
  // src/compiler/shared/file-compiler/asset-manager.ts
5784
5895
 
5785
5896
 
5786
- var AssetManager = class {
5787
- constructor(fileCompiler, cleanupManager) {
5897
+ var AssetManager = (_class6 = class {
5898
+ constructor(fileCompiler, cleanupManager) {;_class6.prototype.__init10.call(this);
5788
5899
  this.fileCompiler = fileCompiler;
5789
5900
  this.cleanupManager = cleanupManager;
5790
5901
  }
5902
+ // 需要经过管线编译处理的文件类型
5903
+ __init10() {this.pipelineFiles = [".js", ".ts", ".less", ".scss", ".sass"]}
5791
5904
  /**
5792
5905
  * 运行资源文件处理管线
5793
5906
  */
@@ -5800,11 +5913,14 @@ var AssetManager = class {
5800
5913
  const relativeToRoot = normalizePath(this.fileCompiler.relativePath(p));
5801
5914
  const filename = _path2.default.basename(p).toLowerCase();
5802
5915
  const ext = _path2.default.extname(p).toLowerCase();
5803
- if (!_optionalChain([this, 'access', _205 => _205.fileCompiler, 'access', _206 => _206.options, 'access', _207 => _207.output, 'optionalAccess', _208 => _208.ignoreAssets])) {
5916
+ if (!_optionalChain([this, 'access', _207 => _207.fileCompiler, 'access', _208 => _208.options, 'access', _209 => _209.output, 'optionalAccess', _210 => _210.ignoreAssets])) {
5804
5917
  const shouldExclude = Array.from(exclusions).some((pattern) => {
5805
5918
  if (pattern.endsWith(".")) {
5806
5919
  return filename.startsWith(pattern);
5807
5920
  }
5921
+ if (pattern.startsWith(".")) {
5922
+ return ext === pattern;
5923
+ }
5808
5924
  return relativeToRoot === pattern || filename === pattern;
5809
5925
  });
5810
5926
  if (shouldExclude) {
@@ -5815,7 +5931,7 @@ var AssetManager = class {
5815
5931
  }
5816
5932
  if (ext === ".vue") return false;
5817
5933
  const isInsideSrc = p.startsWith(inputPath + _path2.default.sep);
5818
- if (isInsideSrc && (ext === ".js" || ext === ".ts")) {
5934
+ if (isInsideSrc && this.pipelineFiles.includes(ext)) {
5819
5935
  return false;
5820
5936
  }
5821
5937
  return true;
@@ -5867,7 +5983,7 @@ var AssetManager = class {
5867
5983
  cache.target.push(newData);
5868
5984
  }
5869
5985
  }
5870
- };
5986
+ }, _class6);
5871
5987
 
5872
5988
  // src/compiler/shared/file-compiler/cache-manager.ts
5873
5989
  var CacheManager = class {
@@ -5934,10 +6050,10 @@ var CleanupManager = class {
5934
6050
  const removeFn = async (m) => {
5935
6051
  if (key === "sfc" /* SFC */) {
5936
6052
  const meta = m;
5937
- if (!_optionalChain([meta, 'optionalAccess', _209 => _209.output])) return;
6053
+ if (!_optionalChain([meta, 'optionalAccess', _211 => _211.output])) return;
5938
6054
  const { jsx, css } = meta.output;
5939
6055
  await this.fileCompiler.removeOutputFile(jsx.file);
5940
- if (_optionalChain([css, 'optionalAccess', _210 => _210.file])) {
6056
+ if (_optionalChain([css, 'optionalAccess', _212 => _212.file])) {
5941
6057
  await this.fileCompiler.removeOutputFile(css.file);
5942
6058
  }
5943
6059
  } else if (key === "script" /* SCRIPT */ || key === "copied" /* ASSET */) {
@@ -5975,33 +6091,47 @@ var CompilationUnitProcessor = class {
5975
6091
  }
5976
6092
  // 处理编译结果
5977
6093
  resolveResult(result, unit, key) {
5978
- const { fileId, code, hasRoute } = result;
6094
+ const { fileId, code } = result;
5979
6095
  unit.fileId = fileId;
5980
- unit.hasRoute = hasRoute;
5981
- if (key === "sfc" /* SFC */) {
5982
- const component = result;
5983
- const { jsx, css } = component.fileInfo;
5984
- if (css.file) {
5985
- css.file = this.fileCompiler.resolveOutputPath(css.file);
5986
- }
5987
- unit.output = {
5988
- // 添加 jsx 文件信息
5989
- jsx: {
5990
- file: jsx.file,
5991
- code
5992
- },
5993
- css
5994
- // 添加 css 文件信息
5995
- };
5996
- } else if (key === "script" /* SCRIPT */) {
5997
- const { script } = result.fileInfo;
5998
- unit.output = {
5999
- script: {
6000
- file: script.file,
6001
- code
6096
+ const isSFC = key === "sfc" /* SFC */;
6097
+ const isScriptFile = key === "script" /* SCRIPT */;
6098
+ const isStyleFile = key === "style" /* STYLE */;
6099
+ if (isSFC || isScriptFile) {
6100
+ unit.hasRoute = _optionalChain([result, 'optionalAccess', _213 => _213.hasRoute]);
6101
+ }
6102
+ const resolveFileInfo = () => {
6103
+ if (isSFC) {
6104
+ const component = result;
6105
+ const { jsx, css } = component.fileInfo;
6106
+ if (css.file) {
6107
+ css.file = this.fileCompiler.resolveOutputPath(css.file);
6002
6108
  }
6003
- };
6004
- }
6109
+ unit.output = {
6110
+ jsx: {
6111
+ file: jsx.file,
6112
+ code
6113
+ },
6114
+ css
6115
+ };
6116
+ } else if (isScriptFile) {
6117
+ const { script } = result.fileInfo;
6118
+ unit.output = {
6119
+ script: {
6120
+ file: _optionalChain([script, 'optionalAccess', _214 => _214.file]),
6121
+ code
6122
+ }
6123
+ };
6124
+ } else if (isStyleFile) {
6125
+ const { style } = result.fileInfo;
6126
+ unit.output = {
6127
+ style: {
6128
+ file: style.file,
6129
+ code
6130
+ }
6131
+ };
6132
+ }
6133
+ };
6134
+ resolveFileInfo();
6005
6135
  }
6006
6136
  /**
6007
6137
  * 将编译产物写入磁盘
@@ -6018,6 +6148,10 @@ var CompilationUnitProcessor = class {
6018
6148
  if (css.file && css.code) {
6019
6149
  await this.fileCompiler.writeFileWithDir(css.file, css.code);
6020
6150
  }
6151
+ } else if (key === "style" /* STYLE */) {
6152
+ const { style } = output;
6153
+ file = style.file;
6154
+ code = style.code;
6021
6155
  } else {
6022
6156
  const { script } = output;
6023
6157
  file = script.file;
@@ -6029,13 +6163,13 @@ var CompilationUnitProcessor = class {
6029
6163
 
6030
6164
  // src/compiler/shared/file-compiler/file-processor.ts
6031
6165
 
6032
- var FileProcessor = (_class6 = class {
6033
- constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class6.prototype.__init10.call(this);
6166
+ var FileProcessor = (_class7 = class {
6167
+ constructor(fileCompiler, compilationUnitProcessor, cacheManager) {;_class7.prototype.__init11.call(this);
6034
6168
  this.fileCompiler = fileCompiler;
6035
6169
  this.compilationUnitProcessor = compilationUnitProcessor;
6036
6170
  this.cacheManager = cacheManager;
6037
6171
  }
6038
- __init10() {this.pkgs = {
6172
+ __init11() {this.pkgs = {
6039
6173
  router: {
6040
6174
  name: PACKAGE_NAME.router,
6041
6175
  version: "^1.0.0"
@@ -6053,11 +6187,17 @@ var FileProcessor = (_class6 = class {
6053
6187
  async processScript(filePath, existingCache) {
6054
6188
  return this.processFile("script" /* SCRIPT */, filePath, existingCache);
6055
6189
  }
6190
+ /**
6191
+ * Process a single style file (this method is called directly in CLI Watch mode)
6192
+ */
6193
+ async processStyle(filePath, existingCache) {
6194
+ return this.processFile("style" /* STYLE */, filePath, existingCache);
6195
+ }
6056
6196
  async processFile(key, filePath, existingCache) {
6057
6197
  const absPath = this.fileCompiler.getAbsPath(filePath);
6058
6198
  const fileMeta = await this.fileCompiler.getFileMeta(absPath);
6059
6199
  const cache = (this.fileCompiler.getIsCache() ? existingCache : void 0) || await this.fileCompiler.loadCache(key);
6060
- const record = _optionalChain([cache, 'optionalAccess', _211 => _211.target, 'access', _212 => _212.find, 'call', _213 => _213((c) => c.file === absPath)]);
6200
+ const record = _optionalChain([cache, 'optionalAccess', _215 => _215.target, 'access', _216 => _216.find, 'call', _217 => _217((c) => c.file === absPath)]);
6061
6201
  const { shouldCompile, hash } = await this.fileCompiler.checkCacheStatus(
6062
6202
  fileMeta,
6063
6203
  record,
@@ -6068,17 +6208,20 @@ var FileProcessor = (_class6 = class {
6068
6208
  if (!source.trim()) return;
6069
6209
  const initUnit = {
6070
6210
  ...fileMeta,
6071
- file: absPath,
6072
- fileId: "",
6073
6211
  source,
6074
- hash: hash || this.fileCompiler.genHash(source),
6075
- output: null
6212
+ type: key,
6213
+ fileId: "",
6214
+ file: absPath,
6215
+ output: void 0,
6216
+ hash: hash || this.fileCompiler.genHash(source)
6076
6217
  };
6077
6218
  const processed = await this.compilationUnitProcessor.resolve(initUnit, key);
6078
- if (_optionalChain([processed, 'optionalAccess', _214 => _214.output])) {
6219
+ if (_optionalChain([processed, 'optionalAccess', _218 => _218.output])) {
6079
6220
  await this.compilationUnitProcessor.saveCompiledFiles(processed, key);
6080
- if (processed.hasRoute) {
6081
- await this.injectVuReactRouteDep();
6221
+ if (key === "sfc" /* SFC */ || key === "script" /* SCRIPT */) {
6222
+ if (_optionalChain([processed, 'optionalAccess', _219 => _219.hasRoute])) {
6223
+ await this.injectVuReactRouteDep();
6224
+ }
6082
6225
  }
6083
6226
  await this.cacheManager.updateCacheIncrementally(processed, key);
6084
6227
  }
@@ -6091,17 +6234,17 @@ var FileProcessor = (_class6 = class {
6091
6234
  pkg["dependencies"][router.name] = router.version;
6092
6235
  await _fs2.default.promises.writeFile(pkgPath, JSON.stringify(pkg, null, 2), "utf-8");
6093
6236
  }
6094
- }, _class6);
6237
+ }, _class7);
6095
6238
 
6096
6239
  // src/compiler/shared/file-compiler/pipeline-manager.ts
6097
6240
 
6098
- var PipelineManager = (_class7 = class {
6099
- constructor(fileCompiler, fileProcessor) {;_class7.prototype.__init11.call(this);
6241
+ var PipelineManager = (_class8 = class {
6242
+ constructor(fileCompiler, fileProcessor) {;_class8.prototype.__init12.call(this);
6100
6243
  this.fileCompiler = fileCompiler;
6101
6244
  this.fileProcessor = fileProcessor;
6102
6245
  this.cleanupManager = new CleanupManager(fileCompiler);
6103
6246
  }
6104
- __init11() {this.skippedCount = 0}
6247
+ __init12() {this.skippedCount = 0}
6105
6248
 
6106
6249
  /**
6107
6250
  * 运行 SFC 编译管线
@@ -6115,15 +6258,30 @@ var PipelineManager = (_class7 = class {
6115
6258
  async runScriptPipeline() {
6116
6259
  return this.runCorePipeline("script" /* SCRIPT */);
6117
6260
  }
6261
+ /**
6262
+ * 运行 Style 编译管线
6263
+ */
6264
+ async runStylePipeline() {
6265
+ return this.runCorePipeline("style" /* STYLE */);
6266
+ }
6118
6267
  /**
6119
6268
  * 核心编译管线
6120
6269
  */
6121
6270
  async runCorePipeline(key) {
6122
6271
  const inputPath = this.fileCompiler.getInputPath();
6272
+ const scriptExtRegex = /\.(js|ts)$/i;
6273
+ const styleExtRegex = /\.(css|less|sass|scss)$/i;
6123
6274
  const files = this.fileCompiler.scanFiles(inputPath, (p) => {
6124
6275
  const ext = _path2.default.extname(p);
6125
- if (key === "sfc" /* SFC */) return ext === ".vue";
6126
- if (key === "script" /* SCRIPT */) return ext === ".js" || ext === ".ts";
6276
+ if (key === "sfc" /* SFC */) {
6277
+ return ext === ".vue";
6278
+ }
6279
+ if (key === "script" /* SCRIPT */) {
6280
+ return scriptExtRegex.test(ext);
6281
+ }
6282
+ if (key === "style" /* STYLE */) {
6283
+ return styleExtRegex.test(ext);
6284
+ }
6127
6285
  return false;
6128
6286
  });
6129
6287
  if (!files.length) return 0;
@@ -6155,20 +6313,20 @@ var PipelineManager = (_class7 = class {
6155
6313
  resetSkippedCount() {
6156
6314
  this.skippedCount = 0;
6157
6315
  }
6158
- }, _class7);
6316
+ }, _class8);
6159
6317
 
6160
6318
  // src/compiler/shared/file-compiler/vite-bootstrapper.ts
6161
6319
 
6162
6320
 
6163
6321
 
6164
6322
 
6165
- var ViteBootstrapper = (_class8 = class {
6166
- constructor(fileCompiler, options) {;_class8.prototype.__init12.call(this);_class8.prototype.__init13.call(this);
6323
+ var ViteBootstrapper = (_class9 = class {
6324
+ constructor(fileCompiler, options) {;_class9.prototype.__init13.call(this);_class9.prototype.__init14.call(this);
6167
6325
  this.fileCompiler = fileCompiler;
6168
6326
  this.options = options;
6169
6327
  }
6170
- __init12() {this.spinner = _ora2.default.call(void 0, )}
6171
- __init13() {this.pkgs = {
6328
+ __init13() {this.spinner = _ora2.default.call(void 0, )}
6329
+ __init14() {this.pkgs = {
6172
6330
  runtime: {
6173
6331
  name: PACKAGE_NAME.runtime,
6174
6332
  version: "^1.0.0"
@@ -6251,7 +6409,7 @@ var ViteBootstrapper = (_class8 = class {
6251
6409
  */
6252
6410
  resolveViteCreateApp() {
6253
6411
  const { output } = this.options;
6254
- const config = _optionalChain([output, 'optionalAccess', _215 => _215.bootstrapVite]);
6412
+ const config = _optionalChain([output, 'optionalAccess', _220 => _220.bootstrapVite]);
6255
6413
  const template = typeof config === "object" ? config.template : "react-ts";
6256
6414
  const outDirName = this.fileCompiler.getOutDirName();
6257
6415
  const cmd = `npm create vite@latest ${outDirName} -- --template ${template}`;
@@ -6261,12 +6419,12 @@ var ViteBootstrapper = (_class8 = class {
6261
6419
  // 隐藏 create-vite 内部的输出日志,保持终端整洁
6262
6420
  });
6263
6421
  }
6264
- }, _class8);
6422
+ }, _class9);
6265
6423
 
6266
6424
  // src/compiler/shared/file-compiler/index.ts
6267
- var FileCompiler = (_class9 = class extends BaseCompiler {
6268
- __init14() {this.skippedCount = 0}
6269
- __init15() {this.spinner = _ora2.default.call(void 0, )}
6425
+ var FileCompiler = (_class10 = class extends BaseCompiler {
6426
+ __init15() {this.skippedCount = 0}
6427
+ __init16() {this.spinner = _ora2.default.call(void 0, )}
6270
6428
  // 管理器实例
6271
6429
 
6272
6430
 
@@ -6283,7 +6441,7 @@ var FileCompiler = (_class9 = class extends BaseCompiler {
6283
6441
  * @see {@link CompilerOptions} 查看完整的选项说明
6284
6442
  */
6285
6443
  constructor(options = {}) {
6286
- super(options);_class9.prototype.__init14.call(this);_class9.prototype.__init15.call(this);;
6444
+ super(options);_class10.prototype.__init15.call(this);_class10.prototype.__init16.call(this);;
6287
6445
  this.initializeManagers();
6288
6446
  }
6289
6447
  /**
@@ -6333,13 +6491,16 @@ var FileCompiler = (_class9 = class extends BaseCompiler {
6333
6491
  this.spinner.start("Compiling script files...");
6334
6492
  const scriptCount = await this.pipelineManager.runScriptPipeline();
6335
6493
  this.spinner.stop();
6494
+ this.spinner.start("Compiling style files...");
6495
+ const styleCount = await this.pipelineManager.runStylePipeline();
6496
+ this.spinner.stop();
6336
6497
  this.spinner.start("Copying assets...");
6337
6498
  const assetCount = await this.assetManager.runAssetPipeline();
6338
6499
  this.spinner.stop();
6339
- await _optionalChain([this, 'access', _216 => _216.options, 'access', _217 => _217.onSuccess, 'optionalCall', _218 => _218()]);
6500
+ await _optionalChain([this, 'access', _221 => _221.options, 'access', _222 => _222.onSuccess, 'optionalCall', _223 => _223()]);
6340
6501
  const endTime = calcElapsedTime(startTime);
6341
6502
  this.printCoreLogs();
6342
- this.showCompileStats(endTime, sfcCount, scriptCount, assetCount);
6503
+ this.showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount);
6343
6504
  } catch (error) {
6344
6505
  this.spinner.stop();
6345
6506
  const endTime = calcElapsedTime(startTime);
@@ -6377,6 +6538,21 @@ var FileCompiler = (_class9 = class extends BaseCompiler {
6377
6538
  async processScript(filePath, existingCache) {
6378
6539
  return this.fileProcessor.processScript(filePath, existingCache);
6379
6540
  }
6541
+ /**
6542
+ * 处理单个 CSS/LESS/SCSS 样式文件
6543
+ *
6544
+ * 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
6545
+ * 支持增量编译,如果文件未变更则跳过编译。
6546
+ *
6547
+ * @async
6548
+ * @param filePath - style 文件的绝对路径
6549
+ * @param existingCache - 可选的预加载缓存对象,用于增量编译
6550
+ * @returns {Promise<ScriptUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
6551
+ * @see {@link FileProcessor.processStyle}
6552
+ */
6553
+ async processStyle(filePath, existingCache) {
6554
+ return this.fileProcessor.processStyle(filePath, existingCache);
6555
+ }
6380
6556
  /**
6381
6557
  * 处理单个文件(Vue 或 Script)
6382
6558
  *
@@ -6466,7 +6642,7 @@ var FileCompiler = (_class9 = class extends BaseCompiler {
6466
6642
  * @param scriptCount - 处理的脚本文件数量
6467
6643
  * @param assetCount - 处理的资源文件数量
6468
6644
  */
6469
- showCompileStats(endTime, sfcCount, scriptCount, assetCount) {
6645
+ showCompileStats(endTime, sfcCount, scriptCount, styleCount, assetCount) {
6470
6646
  const dir = normalizePath(this.relativePath(this.getOuputPath()));
6471
6647
  this.spinner.succeed(`Build completed in ${endTime}`);
6472
6648
  console.info(` Output directory: ${_kleur2.default.dim(dir)}`);
@@ -6477,16 +6653,17 @@ var FileCompiler = (_class9 = class extends BaseCompiler {
6477
6653
  console.info(_kleur2.default.dim(`Skipped ${this.skippedCount} unchanged file(s)`));
6478
6654
  this.resetSkippedCount();
6479
6655
  }
6480
- if (sfcCount || scriptCount || assetCount) {
6656
+ if (sfcCount || scriptCount || styleCount || assetCount) {
6481
6657
  const stats = [];
6482
6658
  if (sfcCount) stats.push(`${sfcCount} SFC(s)`);
6483
6659
  if (scriptCount) stats.push(`${scriptCount} script(s)`);
6660
+ if (styleCount) stats.push(`${styleCount} style(s)`);
6484
6661
  if (assetCount) stats.push(`${assetCount} asset(s)`);
6485
6662
  console.info(_kleur2.default.gray(`Processed ${stats.join(", ")}`));
6486
6663
  }
6487
6664
  console.info();
6488
6665
  }
6489
- }, _class9);
6666
+ }, _class10);
6490
6667
 
6491
6668
  // src/compiler/shared/define-config.ts
6492
6669
  function defineConfig(options) {