balm-core 6.0.0-alpha.3 → 6.0.0-alpha.5

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/index.cjs CHANGED
@@ -71,6 +71,7 @@ __export(index_exports, {
71
71
  isArray: () => isArray,
72
72
  isBoolean: () => isBoolean,
73
73
  isFunction: () => isFunction,
74
+ isManifestFile: () => isManifestFile,
74
75
  isObject: () => isObject,
75
76
  isString: () => isString,
76
77
  localResolve: () => localResolve,
@@ -78,11 +79,15 @@ __export(index_exports, {
78
79
  logger: () => logger,
79
80
  resolveConfig: () => resolveConfig,
80
81
  resolveDefaultEntry: () => resolveDefaultEntry,
82
+ rewriteCssAssetUrls: () => rewriteCssAssetUrls,
83
+ rewriteHtmlAssetPaths: () => rewriteHtmlAssetPaths,
81
84
  runEsbuild: () => runEsbuild,
82
85
  runRollup: () => runRollup,
83
86
  runWebpack: () => runWebpack,
84
87
  setWorkspaces: () => setWorkspaces,
88
+ shouldUseTargetPaths: () => shouldUseTargetPaths,
85
89
  toNamespace: () => toNamespace,
90
+ transformCssUrl: () => transformCssUrl,
86
91
  transformHtmlmin: () => transformHtmlmin,
87
92
  transformLess: () => transformLess,
88
93
  transformPostcss: () => transformPostcss,
@@ -760,7 +765,7 @@ var CleanTask = class extends BaseTask {
760
765
  };
761
766
 
762
767
  // src/tasks/style.ts
763
- var import_node_path10 = __toESM(require("path"), 1);
768
+ var import_node_path11 = __toESM(require("path"), 1);
764
769
 
765
770
  // src/pipeline/pipeline.ts
766
771
  var import_node_path7 = __toESM(require("path"), 1);
@@ -844,7 +849,10 @@ var Pipeline = class _Pipeline {
844
849
  this.transforms.push(async () => {
845
850
  const patternArr = Array.isArray(patterns) ? patterns : [patterns];
846
851
  const posPatterns = patternArr.filter((p) => !p.startsWith("!"));
847
- const ignorePatterns = patternArr.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
852
+ const ignorePatterns = [
853
+ "**/.DS_Store",
854
+ ...patternArr.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
855
+ ];
848
856
  const fileList = [];
849
857
  for (const p of posPatterns) {
850
858
  let patternBase = this.base;
@@ -1098,6 +1106,96 @@ function transformPostcss(options = {}) {
1098
1106
  };
1099
1107
  }
1100
1108
 
1109
+ // src/pipeline/transforms/url.ts
1110
+ var import_node_path10 = __toESM(require("path"), 1);
1111
+ var CSS_ASSET_TYPES = ["img", "font", "media"];
1112
+ var HTML_ASSET_TYPES = ["css", "js", "img", "font", "media"];
1113
+ function escapeRegExp(value) {
1114
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1115
+ }
1116
+ function normalizeSegment(value) {
1117
+ return value ? value.replace(/^\/+|\/+$/g, "") : "";
1118
+ }
1119
+ function shouldUseTargetPaths(config) {
1120
+ return Boolean(config.env?.isProd || !config.inFrontend);
1121
+ }
1122
+ function isManifestFile(file2, config) {
1123
+ const manifestFilename = import_node_path10.default.basename(config.pwa?.manifest || "manifest.json");
1124
+ return file2.basename === manifestFilename || file2.extname.toLowerCase() === ".webmanifest";
1125
+ }
1126
+ function rewriteCssAssetUrls(content, config) {
1127
+ if (!shouldUseTargetPaths(config)) {
1128
+ return content;
1129
+ }
1130
+ let updated = content;
1131
+ for (const type of CSS_ASSET_TYPES) {
1132
+ const source = normalizeSegment(config.paths?.source?.[type]);
1133
+ const target = normalizeSegment(config.paths?.target?.[type]);
1134
+ if (!source || !target) continue;
1135
+ const sourceLeaf = source.split("/").pop();
1136
+ const candidates = Array.from(
1137
+ new Set(
1138
+ [source, sourceLeaf].filter(
1139
+ (item) => Boolean(item && item !== target)
1140
+ )
1141
+ )
1142
+ ).sort((a, b) => b.length - a.length);
1143
+ if (!candidates.length) continue;
1144
+ const alternation = candidates.map(escapeRegExp).join("|");
1145
+ const relativeRegex = new RegExp(
1146
+ `(^|[\\s('",])((?:\\.{2}\\/)+)(?:${alternation})\\/`,
1147
+ "g"
1148
+ );
1149
+ updated = updated.replace(relativeRegex, `$1$2${target}/`);
1150
+ const rootUrlRegex = new RegExp(
1151
+ `(url\\(\\s*['"]?)\\/(?:${alternation})\\/`,
1152
+ "gi"
1153
+ );
1154
+ updated = updated.replace(rootUrlRegex, `$1/${target}/`);
1155
+ }
1156
+ return updated;
1157
+ }
1158
+ function rewriteHtmlAssetPaths(content, config) {
1159
+ if (!shouldUseTargetPaths(config)) {
1160
+ return content;
1161
+ }
1162
+ const sourceMap = /* @__PURE__ */ new Map();
1163
+ for (const type of HTML_ASSET_TYPES) {
1164
+ const source = normalizeSegment(config.paths?.source?.[type]);
1165
+ const target = normalizeSegment(config.paths?.target?.[type]);
1166
+ if (source && target && source !== target) {
1167
+ sourceMap.set(source, target);
1168
+ }
1169
+ }
1170
+ if (!sourceMap.size) {
1171
+ return content;
1172
+ }
1173
+ const alternation = Array.from(sourceMap.keys()).sort((a, b) => b.length - a.length).map(escapeRegExp).join("|");
1174
+ const virtualDir = normalizeSegment(config.assets?.virtualDir);
1175
+ const virtualPrefix = virtualDir ? `\\/${escapeRegExp(virtualDir)}\\/|` : "";
1176
+ const prefixedRegex = new RegExp(
1177
+ `(^|["'\`=(,\\s])(${virtualPrefix}(?:\\.{1,2}\\/)+|\\/)(${alternation})\\/`,
1178
+ "g"
1179
+ );
1180
+ let updated = content.replace(
1181
+ prefixedRegex,
1182
+ (_, lead, prefix, src) => `${lead}${prefix}${sourceMap.get(src)}/`
1183
+ );
1184
+ const bareQuotedRegex = new RegExp(`(["'\`=])(${alternation})\\/`, "g");
1185
+ updated = updated.replace(
1186
+ bareQuotedRegex,
1187
+ (_, lead, src) => `${lead}${sourceMap.get(src)}/`
1188
+ );
1189
+ return updated;
1190
+ }
1191
+ function transformCssUrl(config) {
1192
+ return async (file2) => {
1193
+ if (!/\.css$/i.test(file2.extname)) return file2;
1194
+ file2.contents = Buffer.from(rewriteCssAssetUrls(file2.toString(), config));
1195
+ return file2;
1196
+ };
1197
+ }
1198
+
1101
1199
  // src/tasks/style.ts
1102
1200
  var StyleTask = class extends BaseTask {
1103
1201
  constructor() {
@@ -1105,9 +1203,9 @@ var StyleTask = class extends BaseTask {
1105
1203
  }
1106
1204
  async run(config) {
1107
1205
  const ext = config.styles.extname;
1108
- const srcPattern = import_node_path10.default.join(config.src.css, `**/*.${ext}`);
1206
+ const srcPattern = import_node_path11.default.join(config.src.css, `**/*.${ext}`);
1109
1207
  const isProd = config.env.isProd;
1110
- const pipeline = Pipeline.from([srcPattern, `!${import_node_path10.default.join(config.src.css, "**/_*.scss")}`, `!${import_node_path10.default.join(config.src.css, "**/_*.less")}`], {
1208
+ const pipeline = Pipeline.from([srcPattern, `!${import_node_path11.default.join(config.src.css, "**/_*.scss")}`, `!${import_node_path11.default.join(config.src.css, "**/_*.less")}`], {
1111
1209
  cwd: config.workspace,
1112
1210
  base: config.src.css
1113
1211
  });
@@ -1139,13 +1237,14 @@ var StyleTask = class extends BaseTask {
1139
1237
  ...config.styles.postcssLoaderOptions
1140
1238
  })
1141
1239
  );
1240
+ pipeline.pipe(transformCssUrl(config));
1142
1241
  await pipeline.dest(config.dest.css);
1143
1242
  }
1144
1243
  };
1145
1244
 
1146
1245
  // src/bundler/webpack.ts
1147
1246
  var import_webpack = __toESM(require("webpack"), 1);
1148
- var import_node_path11 = __toESM(require("path"), 1);
1247
+ var import_node_path12 = __toESM(require("path"), 1);
1149
1248
  var import_node_fs3 = require("fs");
1150
1249
  var import_node_module = require("module");
1151
1250
  var import_autoprefixer2 = __toESM(require("autoprefixer"), 1);
@@ -1163,7 +1262,7 @@ var BABEL_CONFIG_FILES = [
1163
1262
  ];
1164
1263
  function resolveModule(pkgName, workspace) {
1165
1264
  try {
1166
- const workspaceRequire = (0, import_node_module.createRequire)(import_node_path11.default.join(workspace, "package.json"));
1265
+ const workspaceRequire = (0, import_node_module.createRequire)(import_node_path12.default.join(workspace, "package.json"));
1167
1266
  return workspaceRequire.resolve(pkgName);
1168
1267
  } catch {
1169
1268
  return coreRequire.resolve(pkgName);
@@ -1171,18 +1270,18 @@ function resolveModule(pkgName, workspace) {
1171
1270
  }
1172
1271
  function resolveWorkspacePaths(paths, workspace) {
1173
1272
  if (!paths || !paths.length) return [];
1174
- return paths.map((p) => import_node_path11.default.isAbsolute(p) ? p : import_node_path11.default.resolve(workspace, p));
1273
+ return paths.map((p) => import_node_path12.default.isAbsolute(p) ? p : import_node_path12.default.resolve(workspace, p));
1175
1274
  }
1176
1275
  function hasBabelConfig(config) {
1177
1276
  if (config.scripts.babelLoaderOptions && Object.keys(config.scripts.babelLoaderOptions).length > 0) {
1178
1277
  return true;
1179
1278
  }
1180
1279
  for (const filename of BABEL_CONFIG_FILES) {
1181
- if ((0, import_node_fs3.existsSync)(import_node_path11.default.join(config.workspace, filename))) {
1280
+ if ((0, import_node_fs3.existsSync)(import_node_path12.default.join(config.workspace, filename))) {
1182
1281
  return true;
1183
1282
  }
1184
1283
  }
1185
- const pkgPath = import_node_path11.default.join(config.workspace, "package.json");
1284
+ const pkgPath = import_node_path12.default.join(config.workspace, "package.json");
1186
1285
  if ((0, import_node_fs3.existsSync)(pkgPath)) {
1187
1286
  try {
1188
1287
  const pkg = JSON.parse((0, import_node_fs3.readFileSync)(pkgPath, "utf-8"));
@@ -1320,7 +1419,7 @@ async function runWebpack(config, customOptions = {}) {
1320
1419
  }
1321
1420
  const rawOutputPath = customOptions.output?.path;
1322
1421
  const isCustomOutput = Boolean(rawOutputPath);
1323
- const outputPath = isCustomOutput ? import_node_path11.default.isAbsolute(rawOutputPath) ? rawOutputPath : import_node_path11.default.resolve(config.workspace, rawOutputPath) : config.dest.base;
1422
+ const outputPath = isCustomOutput ? import_node_path12.default.isAbsolute(rawOutputPath) ? rawOutputPath : import_node_path12.default.resolve(config.workspace, rawOutputPath) : config.dest.base;
1324
1423
  const jsDir = isCustomOutput ? "" : isProd ? config.paths.target.js : config.paths.tmp.js;
1325
1424
  const imgDir = isProd ? config.paths.target.img : config.paths.tmp.img;
1326
1425
  const fontDir = isProd ? config.paths.target.font : config.paths.tmp.font;
@@ -1525,7 +1624,7 @@ var ScriptTask = class extends BaseTask {
1525
1624
  };
1526
1625
 
1527
1626
  // src/tasks/html.ts
1528
- var import_node_path12 = __toESM(require("path"), 1);
1627
+ var import_node_path13 = __toESM(require("path"), 1);
1529
1628
  var import_node_fs4 = require("fs");
1530
1629
  var import_fast_glob3 = __toESM(require("fast-glob"), 1);
1531
1630
 
@@ -1615,17 +1714,17 @@ var HtmlTask = class extends BaseTask {
1615
1714
  const customTemplate = config.scripts.htmlPluginOptions?.template;
1616
1715
  let pipeline;
1617
1716
  if (customTemplate) {
1618
- const templatePath = import_node_path12.default.isAbsolute(customTemplate) ? customTemplate : import_node_path12.default.join(config.workspace, customTemplate);
1717
+ const templatePath = import_node_path13.default.isAbsolute(customTemplate) ? customTemplate : import_node_path13.default.join(config.workspace, customTemplate);
1619
1718
  pipeline = Pipeline.from(templatePath, {
1620
1719
  cwd: config.workspace,
1621
- base: import_node_path12.default.dirname(templatePath)
1720
+ base: import_node_path13.default.dirname(templatePath)
1622
1721
  });
1623
1722
  } else {
1624
1723
  const templateDir = config.scripts.injectHtml ? config.src.base : config.src.html;
1625
- const patterns = [import_node_path12.default.join(templateDir, "*.html")];
1724
+ const patterns = [import_node_path13.default.join(templateDir, "*.html")];
1626
1725
  if (config.pwa.manifest) {
1627
- const manifestPattern = import_node_path12.default.join(templateDir, config.pwa.manifest);
1628
- if ((0, import_node_fs4.existsSync)(import_node_path12.default.isAbsolute(manifestPattern) ? manifestPattern : import_node_path12.default.join(config.workspace, manifestPattern))) {
1726
+ const manifestPattern = import_node_path13.default.join(templateDir, config.pwa.manifest);
1727
+ if ((0, import_node_fs4.existsSync)(import_node_path13.default.isAbsolute(manifestPattern) ? manifestPattern : import_node_path13.default.join(config.workspace, manifestPattern))) {
1629
1728
  patterns.push(manifestPattern);
1630
1729
  }
1631
1730
  }
@@ -1642,67 +1741,10 @@ var HtmlTask = class extends BaseTask {
1642
1741
  return file2;
1643
1742
  });
1644
1743
  }
1645
- if (config.env.isProd) {
1744
+ if (shouldUseTargetPaths(config)) {
1646
1745
  pipeline.pipe(async (file2) => {
1647
- if (/\.html$/i.test(file2.extname)) {
1648
- let content = file2.toString();
1649
- if (config.paths.source.css && config.paths.target.css && config.paths.source.css !== config.paths.target.css) {
1650
- content = content.replaceAll(
1651
- `/${config.paths.source.css}/`,
1652
- `/${config.paths.target.css}/`
1653
- );
1654
- content = content.replaceAll(
1655
- `"${config.paths.source.css}/`,
1656
- `"${config.paths.target.css}/`
1657
- );
1658
- content = content.replaceAll(
1659
- `'${config.paths.source.css}/`,
1660
- `'${config.paths.target.css}/`
1661
- );
1662
- }
1663
- if (config.paths.source.js && config.paths.target.js && config.paths.source.js !== config.paths.target.js) {
1664
- content = content.replaceAll(
1665
- `/${config.paths.source.js}/`,
1666
- `/${config.paths.target.js}/`
1667
- );
1668
- content = content.replaceAll(
1669
- `"${config.paths.source.js}/`,
1670
- `"${config.paths.target.js}/`
1671
- );
1672
- content = content.replaceAll(
1673
- `'${config.paths.source.js}/`,
1674
- `'${config.paths.target.js}/`
1675
- );
1676
- }
1677
- if (config.paths.source.img && config.paths.target.img && config.paths.source.img !== config.paths.target.img) {
1678
- content = content.replaceAll(
1679
- `/${config.paths.source.img}/`,
1680
- `/${config.paths.target.img}/`
1681
- );
1682
- content = content.replaceAll(
1683
- `"${config.paths.source.img}/`,
1684
- `"${config.paths.target.img}/`
1685
- );
1686
- content = content.replaceAll(
1687
- `'${config.paths.source.img}/`,
1688
- `'${config.paths.target.img}/`
1689
- );
1690
- }
1691
- if (config.paths.source.font && config.paths.target.font && config.paths.source.font !== config.paths.target.font) {
1692
- content = content.replaceAll(
1693
- `/${config.paths.source.font}/`,
1694
- `/${config.paths.target.font}/`
1695
- );
1696
- content = content.replaceAll(
1697
- `"${config.paths.source.font}/`,
1698
- `"${config.paths.target.font}/`
1699
- );
1700
- content = content.replaceAll(
1701
- `'${config.paths.source.font}/`,
1702
- `'${config.paths.target.font}/`
1703
- );
1704
- }
1705
- file2.contents = Buffer.from(content);
1746
+ if (/\.html$/i.test(file2.extname) || isManifestFile(file2, config)) {
1747
+ file2.contents = Buffer.from(rewriteHtmlAssetPaths(file2.toString(), config));
1706
1748
  }
1707
1749
  return file2;
1708
1750
  });
@@ -1723,7 +1765,7 @@ var HtmlTask = class extends BaseTask {
1723
1765
  )
1724
1766
  ).map((entryName) => {
1725
1767
  let actualFilename = `${entryName}.js`;
1726
- const hasUnhashed = (0, import_node_fs4.existsSync)(import_node_path12.default.join(destJsFolder, actualFilename));
1768
+ const hasUnhashed = (0, import_node_fs4.existsSync)(import_node_path13.default.join(destJsFolder, actualFilename));
1727
1769
  let found = hasUnhashed;
1728
1770
  try {
1729
1771
  const matched = import_fast_glob3.default.sync(`${entryName}.*.js`, { cwd: destJsFolder });
@@ -1822,36 +1864,36 @@ ${LIVE_RELOAD_SCRIPT}`;
1822
1864
  };
1823
1865
 
1824
1866
  // src/tasks/copy.ts
1825
- var import_node_path14 = __toESM(require("path"), 1);
1867
+ var import_node_path15 = __toESM(require("path"), 1);
1826
1868
 
1827
1869
  // src/pipeline/transforms/rename.ts
1828
- var import_node_path13 = __toESM(require("path"), 1);
1870
+ var import_node_path14 = __toESM(require("path"), 1);
1829
1871
  function transformRename(options = {}) {
1830
1872
  return async (file2) => {
1831
1873
  if (typeof options === "string") {
1832
- file2.path = import_node_path13.default.resolve(import_node_path13.default.dirname(file2.path), options);
1874
+ file2.path = import_node_path14.default.resolve(import_node_path14.default.dirname(file2.path), options);
1833
1875
  return file2;
1834
1876
  }
1835
1877
  if (typeof options === "function") {
1836
1878
  const parsed = {
1837
- dirname: import_node_path13.default.dirname(file2.path),
1879
+ dirname: import_node_path14.default.dirname(file2.path),
1838
1880
  basename: file2.stem,
1839
1881
  extname: file2.extname
1840
1882
  };
1841
1883
  const result = options(parsed);
1842
1884
  if (result) {
1843
- if (result.dirname) file2.path = import_node_path13.default.join(result.dirname, import_node_path13.default.basename(file2.path));
1885
+ if (result.dirname) file2.path = import_node_path14.default.join(result.dirname, import_node_path14.default.basename(file2.path));
1844
1886
  if (result.basename) file2.stem = result.basename;
1845
1887
  if (result.extname) file2.extname = result.extname;
1846
1888
  }
1847
1889
  return file2;
1848
1890
  }
1849
1891
  const { dirname, prefix = "", basename, suffix = "", extname } = options;
1850
- const currentDir = dirname ? import_node_path13.default.resolve(file2.cwd, dirname) : import_node_path13.default.dirname(file2.path);
1892
+ const currentDir = dirname ? import_node_path14.default.resolve(file2.cwd, dirname) : import_node_path14.default.dirname(file2.path);
1851
1893
  const base = basename !== void 0 ? basename : file2.stem;
1852
1894
  const ext = extname !== void 0 ? extname : file2.extname;
1853
1895
  const dotExt = ext ? ext.startsWith(".") ? ext : `.${ext}` : "";
1854
- file2.path = import_node_path13.default.join(currentDir, `${prefix}${base}${suffix}${dotExt}`);
1896
+ file2.path = import_node_path14.default.join(currentDir, `${prefix}${base}${suffix}${dotExt}`);
1855
1897
  return file2;
1856
1898
  };
1857
1899
  }
@@ -1870,13 +1912,13 @@ var CopyTask = class extends BaseTask {
1870
1912
  if (this.options.rename) {
1871
1913
  pipeline.pipe(transformRename(this.options.rename));
1872
1914
  }
1873
- const outDir = import_node_path14.default.isAbsolute(this.options.output) ? this.options.output : import_node_path14.default.join(config.workspace, this.options.output);
1915
+ const outDir = import_node_path15.default.isAbsolute(this.options.output) ? this.options.output : import_node_path15.default.join(config.workspace, this.options.output);
1874
1916
  await pipeline.dest(outDir);
1875
1917
  }
1876
1918
  };
1877
1919
 
1878
1920
  // src/tasks/remove.ts
1879
- var import_node_path15 = __toESM(require("path"), 1);
1921
+ var import_node_path16 = __toESM(require("path"), 1);
1880
1922
  var RemoveTask = class extends BaseTask {
1881
1923
  target;
1882
1924
  constructor(target) {
@@ -1886,7 +1928,7 @@ var RemoveTask = class extends BaseTask {
1886
1928
  async run(config) {
1887
1929
  const targets = Array.isArray(this.target) ? this.target : [this.target];
1888
1930
  const resolvedTargets = targets.map(
1889
- (t) => import_node_path15.default.isAbsolute(t) ? t : import_node_path15.default.join(config.workspace, t)
1931
+ (t) => import_node_path16.default.isAbsolute(t) ? t : import_node_path16.default.join(config.workspace, t)
1890
1932
  );
1891
1933
  const deleted = await file.remove(resolvedTargets);
1892
1934
  logger.warn("remove", `Removed: ${deleted.join(", ")}`);
@@ -1894,7 +1936,7 @@ var RemoveTask = class extends BaseTask {
1894
1936
  };
1895
1937
 
1896
1938
  // src/tasks/replace.ts
1897
- var import_node_path16 = __toESM(require("path"), 1);
1939
+ var import_node_path17 = __toESM(require("path"), 1);
1898
1940
  var ReplaceTask = class extends BaseTask {
1899
1941
  taskOptions;
1900
1942
  constructor(taskOptions) {
@@ -1906,7 +1948,7 @@ var ReplaceTask = class extends BaseTask {
1906
1948
  cwd: config.workspace
1907
1949
  });
1908
1950
  pipeline.pipe(transformReplace(this.taskOptions.options));
1909
- const outDir = import_node_path16.default.isAbsolute(this.taskOptions.output) ? this.taskOptions.output : import_node_path16.default.join(config.workspace, this.taskOptions.output);
1951
+ const outDir = import_node_path17.default.isAbsolute(this.taskOptions.output) ? this.taskOptions.output : import_node_path17.default.join(config.workspace, this.taskOptions.output);
1910
1952
  await pipeline.dest(outDir);
1911
1953
  }
1912
1954
  };
@@ -1916,12 +1958,12 @@ var import_fast_glob4 = __toESM(require("fast-glob"), 1);
1916
1958
  var import_promises3 = __toESM(require("fs/promises"), 1);
1917
1959
 
1918
1960
  // src/pipeline/transforms/cache.ts
1919
- var import_node_path17 = __toESM(require("path"), 1);
1961
+ var import_node_path18 = __toESM(require("path"), 1);
1920
1962
  var import_picomatch = __toESM(require("picomatch"), 1);
1921
1963
  function matchesAny(filePath, rules) {
1922
1964
  if (!rules || !rules.length) return false;
1923
1965
  const normalized = filePath.replace(/\\/g, "/");
1924
- const baseName = import_node_path17.default.basename(normalized);
1966
+ const baseName = import_node_path18.default.basename(normalized);
1925
1967
  for (const rawRule of rules) {
1926
1968
  if (typeof rawRule === "string") {
1927
1969
  const rule = rawRule.replace(/\\/g, "/");
@@ -1946,6 +1988,7 @@ var AssetRevisioner = class {
1946
1988
  "*.webmanifest",
1947
1989
  "robots.txt",
1948
1990
  "*.ico",
1991
+ "*.map",
1949
1992
  "workbox-sw.js",
1950
1993
  "workbox-sw.js.map",
1951
1994
  "service-worker.js",
@@ -1966,40 +2009,76 @@ var AssetRevisioner = class {
1966
2009
  }
1967
2010
  }
1968
2011
  process(files) {
2012
+ this.manifest = {};
1969
2013
  const hashLength = this.options.hashLength || 8;
2014
+ const alreadyHashedRegex = hashLength === 8 ? /\.[a-f0-9]{8}$/i : new RegExp(`\\.(?:[a-f0-9]{8}|[a-f0-9]{${hashLength}})$`, "i");
2015
+ const alreadyHashedExtRegex = hashLength === 8 ? /\.[a-f0-9]{8}(\.[^.]+)$/i : new RegExp(`\\.(?:[a-f0-9]{8}|[a-f0-9]{${hashLength}})(\\.[^.]+)$`, "i");
1970
2016
  const outputFiles = [];
2017
+ const renames = [];
2018
+ const renamedOrigs = /* @__PURE__ */ new Set();
2019
+ const alreadyHashedUniques = /* @__PURE__ */ new Map();
1971
2020
  for (const file2 of files) {
1972
- const origRelative = file2.relative;
2021
+ const origRelative = file2.relative.replace(/\\/g, "/");
1973
2022
  file2.revPathOriginal = file2.path;
1974
- const alreadyHashed = /\.[a-f0-9]{8}$/i.test(file2.stem);
2023
+ const alreadyHashed = alreadyHashedRegex.test(file2.stem);
1975
2024
  const shouldRename = !alreadyHashed && !matchesAny(file2.path, this.options.dontRenameFile) && !matchesAny(file2.relative, this.options.dontRenameFile);
1976
2025
  if (shouldRename) {
1977
2026
  const fileHash = file.hash(file2.contents, hashLength);
1978
- const dir = import_node_path17.default.dirname(file2.path);
2027
+ const dir = import_node_path18.default.dirname(file2.path);
1979
2028
  const newFilename = `${file2.stem}.${fileHash}${file2.extname}`;
1980
- file2.path = import_node_path17.default.join(dir, newFilename);
2029
+ file2.path = import_node_path18.default.join(dir, newFilename);
1981
2030
  }
2031
+ const revedRelative = file2.relative.replace(/\\/g, "/");
1982
2032
  if (alreadyHashed) {
1983
- const unhashedRelative = file2.relative.replace(/\.[a-f0-9]{8}(\.[^.]+)$/i, "$1");
1984
- this.manifest[unhashedRelative] = file2.relative;
2033
+ const unhashedRelative = revedRelative.replace(alreadyHashedExtRegex, "$1");
2034
+ alreadyHashedUniques.set(
2035
+ unhashedRelative,
2036
+ alreadyHashedUniques.has(unhashedRelative) ? null : revedRelative
2037
+ );
2038
+ } else if (origRelative !== revedRelative) {
2039
+ renames.push([origRelative, revedRelative]);
2040
+ renamedOrigs.add(origRelative);
1985
2041
  }
1986
- this.manifest[origRelative] = file2.relative;
2042
+ this.manifest[origRelative] = revedRelative;
1987
2043
  outputFiles.push(file2);
1988
2044
  }
1989
- const manifestEntries = Object.entries(this.manifest).filter(([orig, reved]) => orig !== reved).sort((a, b) => b[0].length - a[0].length);
1990
- for (const file2 of outputFiles) {
1991
- const shouldUpdate = !matchesAny(file2.path, this.options.dontUpdateReference) && !matchesAny(file2.relative, this.options.dontUpdateReference);
1992
- if (shouldUpdate && /\.(html|css|js)$/i.test(file2.extname)) {
1993
- let content = file2.toString();
1994
- for (const [orig, reved] of manifestEntries) {
1995
- content = content.replaceAll(orig, reved);
1996
- const origBase = import_node_path17.default.basename(orig);
1997
- const revedBase = import_node_path17.default.basename(reved);
1998
- const escapedBase = origBase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1999
- const baseRegex = new RegExp(`${escapedBase}(?![a-zA-Z0-9_])`, "g");
2000
- content = content.replace(baseRegex, revedBase);
2045
+ const lookup = /* @__PURE__ */ new Map();
2046
+ for (const [unhashedRelative, revedRelative] of alreadyHashedUniques) {
2047
+ if (revedRelative && !renamedOrigs.has(unhashedRelative) && unhashedRelative !== revedRelative) {
2048
+ this.manifest[unhashedRelative] = revedRelative;
2049
+ lookup.set(unhashedRelative, revedRelative);
2050
+ }
2051
+ }
2052
+ const basenameCounts = /* @__PURE__ */ new Map();
2053
+ for (const [orig] of renames) {
2054
+ const base = import_node_path18.default.posix.basename(orig);
2055
+ basenameCounts.set(base, (basenameCounts.get(base) || 0) + 1);
2056
+ }
2057
+ for (const [orig, reved] of renames) {
2058
+ const origBase = import_node_path18.default.posix.basename(orig);
2059
+ const revedBase = import_node_path18.default.posix.basename(reved);
2060
+ if (basenameCounts.get(origBase) === 1 && !lookup.has(origBase)) {
2061
+ lookup.set(origBase, revedBase);
2062
+ }
2063
+ }
2064
+ for (const [orig, reved] of renames) {
2065
+ lookup.set(orig, reved);
2066
+ }
2067
+ if (lookup.size > 0) {
2068
+ const patterns = [...lookup.keys()].sort((a, b) => b.length - a.length).map((key) => key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
2069
+ const replaceRegex = new RegExp(
2070
+ `(?<![a-zA-Z0-9_.@-])(?:${patterns.join("|")})(?![a-zA-Z0-9_.@-])`,
2071
+ "g"
2072
+ );
2073
+ for (const file2 of outputFiles) {
2074
+ const shouldUpdate = !matchesAny(file2.path, this.options.dontUpdateReference) && !matchesAny(file2.relative, this.options.dontUpdateReference);
2075
+ if (shouldUpdate && /\.(html|css|js)$/i.test(file2.extname)) {
2076
+ const content = file2.toString();
2077
+ const updated = content.replace(replaceRegex, (matched) => lookup.get(matched) || matched);
2078
+ if (updated !== content) {
2079
+ file2.contents = Buffer.from(updated);
2080
+ }
2001
2081
  }
2002
- file2.contents = Buffer.from(content);
2003
2082
  }
2004
2083
  }
2005
2084
  const manifestName = this.options.fileNameManifest || "rev-manifest.json";
@@ -2007,7 +2086,7 @@ var AssetRevisioner = class {
2007
2086
  const manifestFile = new VirtualFile({
2008
2087
  cwd: files[0]?.cwd || process.cwd(),
2009
2088
  base: firstBase,
2010
- path: import_node_path17.default.join(firstBase, manifestName),
2089
+ path: import_node_path18.default.join(firstBase, manifestName),
2011
2090
  contents: JSON.stringify(this.manifest, null, 2)
2012
2091
  });
2013
2092
  outputFiles.push(manifestFile);
@@ -2039,17 +2118,22 @@ var CacheTask = class extends BaseTask {
2039
2118
  logger.warn("cache", "No files found to cache");
2040
2119
  return;
2041
2120
  }
2121
+ const originalContents = /* @__PURE__ */ new Map();
2042
2122
  const virtualFiles = await Promise.all(
2043
2123
  filesToRev.map(async (filePath) => {
2044
2124
  const buffer = await import_promises3.default.readFile(filePath);
2045
- return new VirtualFile({
2125
+ const vFile = new VirtualFile({
2046
2126
  cwd: config.workspace,
2047
2127
  base: destDir,
2048
2128
  path: filePath,
2049
2129
  contents: buffer
2050
2130
  });
2131
+ originalContents.set(vFile, buffer);
2132
+ return vFile;
2051
2133
  })
2052
2134
  );
2135
+ const isWebpack = !config.scripts.bundler || config.scripts.bundler === "webpack" /* webpack */;
2136
+ const webpackOwnedGlobs = isWebpack ? [`${config.paths.target.js}/**/*`, `${config.paths.target.css}/async/**/*`] : [];
2053
2137
  const cacheOptions = {
2054
2138
  ...config.assets.options,
2055
2139
  dontRenameFile: [
@@ -2059,13 +2143,19 @@ var CacheTask = class extends BaseTask {
2059
2143
  "*.webmanifest",
2060
2144
  "robots.txt",
2061
2145
  "*.ico",
2146
+ "*.map",
2062
2147
  "icons/*",
2063
2148
  "**/icons/**",
2064
2149
  "sw.js",
2065
2150
  "service-worker.js",
2066
2151
  "workbox-sw.js",
2152
+ ...webpackOwnedGlobs,
2067
2153
  ...config.assets.excludes || [],
2068
2154
  ...config.assets.options?.dontRenameFile || []
2155
+ ],
2156
+ dontUpdateReference: [
2157
+ ...webpackOwnedGlobs,
2158
+ ...config.assets.options?.dontUpdateReference || []
2069
2159
  ]
2070
2160
  };
2071
2161
  const revisioner = new AssetRevisioner(cacheOptions);
@@ -2076,14 +2166,19 @@ var CacheTask = class extends BaseTask {
2076
2166
  }
2077
2167
  }
2078
2168
  for (const vFile of resultFiles) {
2079
- await file.writeFile(vFile.path, vFile.contents);
2169
+ const origBuf = originalContents.get(vFile);
2170
+ const isRenamed = Boolean(vFile.revPathOriginal && vFile.revPathOriginal !== vFile.path);
2171
+ const isUpdated = !origBuf || !origBuf.equals(vFile.contents);
2172
+ if (isRenamed || isUpdated) {
2173
+ await file.writeFile(vFile.path, vFile.contents);
2174
+ }
2080
2175
  }
2081
2176
  logger.success("cache", "Asset revisioning and rev-manifest.json completed");
2082
2177
  }
2083
2178
  };
2084
2179
 
2085
2180
  // src/tasks/publish.ts
2086
- var import_node_path18 = __toESM(require("path"), 1);
2181
+ var import_node_path19 = __toESM(require("path"), 1);
2087
2182
  var PublishTask = class extends BaseTask {
2088
2183
  options;
2089
2184
  constructor(options = {}) {
@@ -2104,17 +2199,17 @@ var PublishTask = class extends BaseTask {
2104
2199
  await this.publishItem(config, input, output, renameOptions);
2105
2200
  } else {
2106
2201
  const srcDir = config.dest.base;
2107
- const targetDir = config.assets.static || import_node_path18.default.join(config.assets.root, config.assets.mainDir);
2202
+ const targetDir = config.assets.static || import_node_path19.default.join(config.assets.root, config.assets.mainDir);
2108
2203
  const pipeline = Pipeline.from(["**/*"], {
2109
2204
  cwd: srcDir,
2110
2205
  base: srcDir
2111
2206
  });
2112
- await pipeline.dest(import_node_path18.default.resolve(config.workspace, targetDir));
2207
+ await pipeline.dest(import_node_path19.default.resolve(config.workspace, targetDir));
2113
2208
  }
2114
2209
  }
2115
2210
  async publishItem(config, input, output, rename) {
2116
- const srcPath = import_node_path18.default.isAbsolute(input) ? input : import_node_path18.default.join(config.dest.base, input);
2117
- const destDir = import_node_path18.default.isAbsolute(output) ? output : import_node_path18.default.join(config.workspace, config.assets.root, output);
2211
+ const srcPath = import_node_path19.default.isAbsolute(input) ? input : import_node_path19.default.join(config.dest.base, input);
2212
+ const destDir = import_node_path19.default.isAbsolute(output) ? output : import_node_path19.default.join(config.workspace, config.assets.root, output);
2118
2213
  const pipeline = Pipeline.from(srcPath, {
2119
2214
  cwd: config.dest.base
2120
2215
  });
@@ -2126,7 +2221,7 @@ var PublishTask = class extends BaseTask {
2126
2221
  };
2127
2222
 
2128
2223
  // src/tasks/pwa.ts
2129
- var import_node_path19 = __toESM(require("path"), 1);
2224
+ var import_node_path20 = __toESM(require("path"), 1);
2130
2225
  var import_promises4 = __toESM(require("fs/promises"), 1);
2131
2226
  var import_node_fs5 = require("fs");
2132
2227
  var import_node_module2 = require("module");
@@ -2139,12 +2234,12 @@ var PwaTask = class extends BaseTask {
2139
2234
  }
2140
2235
  async run(config) {
2141
2236
  const globDirectory = config.dest.base;
2142
- const swDest = import_node_path19.default.join(globDirectory, config.pwa.swDestFilename);
2143
- const swSrc = import_node_path19.default.join(config.src.base, config.pwa.swSrcFilename);
2237
+ const swDest = import_node_path20.default.join(globDirectory, config.pwa.swDestFilename);
2238
+ const swSrc = import_node_path20.default.join(config.src.base, config.pwa.swSrcFilename);
2144
2239
  const require2 = (0, import_node_module2.createRequire)(importMetaUrl);
2145
2240
  const candidatePaths = [
2146
- import_node_path19.default.join(config.workspace, "node_modules/workbox-sw/build/workbox-sw.js"),
2147
- import_node_path19.default.join(config.workspace, "node_modules/workbox-sw/controllers/WorkboxSW.mjs")
2241
+ import_node_path20.default.join(config.workspace, "node_modules/workbox-sw/build/workbox-sw.js"),
2242
+ import_node_path20.default.join(config.workspace, "node_modules/workbox-sw/controllers/WorkboxSW.mjs")
2148
2243
  ];
2149
2244
  try {
2150
2245
  const resolved = require2.resolve("workbox-sw/build/workbox-sw.js");
@@ -2153,12 +2248,12 @@ var PwaTask = class extends BaseTask {
2153
2248
  }
2154
2249
  try {
2155
2250
  const resolvedPkg = require2.resolve("workbox-sw");
2156
- candidatePaths.push(import_node_path19.default.join(import_node_path19.default.dirname(resolvedPkg), "build/workbox-sw.js"));
2251
+ candidatePaths.push(import_node_path20.default.join(import_node_path20.default.dirname(resolvedPkg), "build/workbox-sw.js"));
2157
2252
  } catch {
2158
2253
  }
2159
2254
  for (const p of candidatePaths) {
2160
2255
  if ((0, import_node_fs5.existsSync)(p)) {
2161
- const destFile = import_node_path19.default.join(globDirectory, "workbox-sw.js");
2256
+ const destFile = import_node_path20.default.join(globDirectory, "workbox-sw.js");
2162
2257
  await import_promises4.default.copyFile(p, destFile);
2163
2258
  break;
2164
2259
  }
@@ -2194,7 +2289,7 @@ var PwaTask = class extends BaseTask {
2194
2289
 
2195
2290
  // src/tasks/zip.ts
2196
2291
  var import_node_fs6 = __toESM(require("fs"), 1);
2197
- var import_node_path20 = __toESM(require("path"), 1);
2292
+ var import_node_path21 = __toESM(require("path"), 1);
2198
2293
  var import_archiver = __toESM(require("archiver"), 1);
2199
2294
  var import_fast_glob5 = __toESM(require("fast-glob"), 1);
2200
2295
  var ZipTask = class extends BaseTask {
@@ -2205,9 +2300,9 @@ var ZipTask = class extends BaseTask {
2205
2300
  }
2206
2301
  async run(config) {
2207
2302
  const input = this.options.input || config.dest.base;
2208
- const outputDir = this.options.output ? import_node_path20.default.isAbsolute(this.options.output) ? this.options.output : import_node_path20.default.join(config.workspace, this.options.output) : config.workspace;
2303
+ const outputDir = this.options.output ? import_node_path21.default.isAbsolute(this.options.output) ? this.options.output : import_node_path21.default.join(config.workspace, this.options.output) : config.workspace;
2209
2304
  const filename = this.options.filename || "archive.zip";
2210
- const zipPath = import_node_path20.default.join(outputDir, filename);
2305
+ const zipPath = import_node_path21.default.join(outputDir, filename);
2211
2306
  await file.ensureDir(outputDir);
2212
2307
  return new Promise((resolve, reject) => {
2213
2308
  const outputStream = import_node_fs6.default.createWriteStream(zipPath);
@@ -2228,18 +2323,18 @@ var ZipTask = class extends BaseTask {
2228
2323
  const base = item.split("*")[0].replace(/\/+$/, "") || ".";
2229
2324
  const matched = import_fast_glob5.default.sync(item, { cwd: config.workspace, onlyFiles: true, dot: true });
2230
2325
  for (const relPath of matched) {
2231
- const fullFilePath = import_node_path20.default.join(config.workspace, relPath);
2232
- const zipName = import_node_path20.default.relative(base, relPath);
2326
+ const fullFilePath = import_node_path21.default.join(config.workspace, relPath);
2327
+ const zipName = import_node_path21.default.relative(base, relPath);
2233
2328
  archive.file(fullFilePath, { name: zipName });
2234
2329
  }
2235
2330
  } else {
2236
- const fullPath = import_node_path20.default.isAbsolute(item) ? item : import_node_path20.default.join(config.workspace, item);
2331
+ const fullPath = import_node_path21.default.isAbsolute(item) ? item : import_node_path21.default.join(config.workspace, item);
2237
2332
  if (import_node_fs6.default.existsSync(fullPath)) {
2238
2333
  const stat = import_node_fs6.default.statSync(fullPath);
2239
2334
  if (stat.isDirectory()) {
2240
2335
  archive.directory(fullPath, false);
2241
2336
  } else {
2242
- archive.file(fullPath, { name: import_node_path20.default.basename(fullPath) });
2337
+ archive.file(fullPath, { name: import_node_path21.default.basename(fullPath) });
2243
2338
  }
2244
2339
  }
2245
2340
  }
@@ -2250,7 +2345,7 @@ var ZipTask = class extends BaseTask {
2250
2345
  };
2251
2346
 
2252
2347
  // src/tasks/ftp.ts
2253
- var import_node_path21 = __toESM(require("path"), 1);
2348
+ var import_node_path22 = __toESM(require("path"), 1);
2254
2349
  var import_ssh2 = require("ssh2");
2255
2350
  var import_fast_glob6 = __toESM(require("fast-glob"), 1);
2256
2351
  var FtpTask = class extends BaseTask {
@@ -2286,8 +2381,8 @@ var FtpTask = class extends BaseTask {
2286
2381
  }
2287
2382
  let pending = files.length;
2288
2383
  for (const file2 of files) {
2289
- const rel = import_node_path21.default.relative(config.workspace, file2);
2290
- const remoteFile = import_node_path21.default.posix.join(options.remotePath, rel);
2384
+ const rel = import_node_path22.default.relative(config.workspace, file2);
2385
+ const remoteFile = import_node_path22.default.posix.join(options.remotePath, rel);
2291
2386
  sftp.fastPut(file2, remoteFile, (putErr) => {
2292
2387
  if (putErr) {
2293
2388
  logger.error("ftp", `Failed uploading ${file2}: ${putErr.message}`);
@@ -2315,7 +2410,7 @@ var FtpTask = class extends BaseTask {
2315
2410
  // src/tasks/server.ts
2316
2411
  var import_node_http = __toESM(require("http"), 1);
2317
2412
  var import_node_fs8 = __toESM(require("fs"), 1);
2318
- var import_node_path23 = __toESM(require("path"), 1);
2413
+ var import_node_path24 = __toESM(require("path"), 1);
2319
2414
  var import_connect = __toESM(require("connect"), 1);
2320
2415
  var import_serve_static = __toESM(require("serve-static"), 1);
2321
2416
  var import_ws = require("ws");
@@ -2323,7 +2418,7 @@ var import_http_proxy_middleware = require("http-proxy-middleware");
2323
2418
 
2324
2419
  // src/watcher/index.ts
2325
2420
  var import_node_fs7 = __toESM(require("fs"), 1);
2326
- var import_node_path22 = __toESM(require("path"), 1);
2421
+ var import_node_path23 = __toESM(require("path"), 1);
2327
2422
  var import_picocolors3 = __toESM(require("picocolors"), 1);
2328
2423
  var FileWatcher = class {
2329
2424
  config;
@@ -2348,10 +2443,10 @@ var FileWatcher = class {
2348
2443
  ...this.config.scripts.includeJsResource || [],
2349
2444
  ...this.config.styles.atImportPaths || []
2350
2445
  ];
2351
- const resolved = candidates.filter(Boolean).map((dir) => import_node_path22.default.isAbsolute(dir) ? dir : import_node_path22.default.resolve(this.config.workspace, dir)).filter((dir) => import_node_fs7.default.existsSync(dir) && !dir.includes(`${import_node_path22.default.sep}node_modules`));
2446
+ const resolved = candidates.filter(Boolean).map((dir) => import_node_path23.default.isAbsolute(dir) ? dir : import_node_path23.default.resolve(this.config.workspace, dir)).filter((dir) => import_node_fs7.default.existsSync(dir) && !dir.includes(`${import_node_path23.default.sep}node_modules`));
2352
2447
  const unique = Array.from(new Set(resolved)).sort((a, b) => a.length - b.length);
2353
2448
  return unique.filter(
2354
- (dir, index) => !unique.slice(0, index).some((parent) => dir.startsWith(`${parent}${import_node_path22.default.sep}`))
2449
+ (dir, index) => !unique.slice(0, index).some((parent) => dir.startsWith(`${parent}${import_node_path23.default.sep}`))
2355
2450
  );
2356
2451
  }
2357
2452
  start() {
@@ -2469,9 +2564,9 @@ var ServerTask = class extends BaseTask {
2469
2564
  app.use((req, res, next) => {
2470
2565
  if (req.url === "/manifest.json" || req.url?.endsWith("/manifest.json")) {
2471
2566
  const candidates = [
2472
- import_node_path23.default.join(config.dest.base, "manifest.json"),
2473
- import_node_path23.default.join(config.src.base, "manifest.json"),
2474
- import_node_path23.default.join(config.workspace, "manifest.json")
2567
+ import_node_path24.default.join(config.dest.base, "manifest.json"),
2568
+ import_node_path24.default.join(config.src.base, "manifest.json"),
2569
+ import_node_path24.default.join(config.workspace, "manifest.json")
2475
2570
  ];
2476
2571
  const file2 = candidates.find((f) => import_node_fs8.default.existsSync(f));
2477
2572
  if (file2) {
@@ -2496,37 +2591,37 @@ var ServerTask = class extends BaseTask {
2496
2591
  if (config.paths.tmp.js && config.paths.tmp.js !== config.paths.source.js) {
2497
2592
  app.use("/" + config.paths.tmp.js, (0, import_serve_static.default)(config.dest.js));
2498
2593
  }
2499
- app.use("/chunk", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.js, "chunk")));
2500
- app.use("/chunk", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "chunk")));
2594
+ app.use("/chunk", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.js, "chunk")));
2595
+ app.use("/chunk", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "chunk")));
2501
2596
  if (config.paths.source.img) {
2502
2597
  app.use(
2503
2598
  "/" + config.paths.source.img,
2504
- (0, import_serve_static.default)(import_node_path23.default.join(config.src.base, config.paths.source.img))
2599
+ (0, import_serve_static.default)(import_node_path24.default.join(config.src.base, config.paths.source.img))
2505
2600
  );
2506
2601
  }
2507
2602
  if (config.paths.tmp.img) {
2508
2603
  app.use("/" + config.paths.tmp.img, (0, import_serve_static.default)(config.dest.img));
2509
2604
  }
2510
- app.use("/img", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "img")));
2511
- app.use("/img", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.js, "img")));
2605
+ app.use("/img", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "img")));
2606
+ app.use("/img", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.js, "img")));
2512
2607
  if (config.paths.source.font) {
2513
2608
  app.use(
2514
2609
  "/" + config.paths.source.font,
2515
- (0, import_serve_static.default)(import_node_path23.default.join(config.src.base, config.paths.source.font))
2610
+ (0, import_serve_static.default)(import_node_path24.default.join(config.src.base, config.paths.source.font))
2516
2611
  );
2517
2612
  }
2518
2613
  if (config.paths.tmp.font) {
2519
2614
  app.use("/" + config.paths.tmp.font, (0, import_serve_static.default)(config.dest.font));
2520
2615
  }
2521
- app.use("/font", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "font")));
2522
- app.use("/font", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.js, "font")));
2523
- app.use("/fonts", (0, import_serve_static.default)(import_node_path23.default.join(config.src.base, "fonts")));
2524
- app.use("/fonts", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "fonts")));
2616
+ app.use("/font", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "font")));
2617
+ app.use("/font", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.js, "font")));
2618
+ app.use("/fonts", (0, import_serve_static.default)(import_node_path24.default.join(config.src.base, "fonts")));
2619
+ app.use("/fonts", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "fonts")));
2525
2620
  if (config.server.serveStatic) {
2526
2621
  const staticEntries = Array.isArray(config.server.serveStatic) ? config.server.serveStatic : [config.server.serveStatic];
2527
2622
  for (const entry of staticEntries) {
2528
2623
  if (typeof entry === "string") {
2529
- const absoluteDir = import_node_path23.default.isAbsolute(entry) ? entry : import_node_path23.default.join(config.workspace, entry);
2624
+ const absoluteDir = import_node_path24.default.isAbsolute(entry) ? entry : import_node_path24.default.join(config.workspace, entry);
2530
2625
  if (import_node_fs8.default.existsSync(absoluteDir)) {
2531
2626
  app.use((0, import_serve_static.default)(absoluteDir));
2532
2627
  }
@@ -2534,7 +2629,7 @@ var ServerTask = class extends BaseTask {
2534
2629
  const route = entry.route ? entry.route.startsWith("/") ? entry.route : `/${entry.route}` : "";
2535
2630
  const dirs = Array.isArray(entry.dir) ? entry.dir : [entry.dir];
2536
2631
  for (const dir of dirs) {
2537
- const absoluteDir = import_node_path23.default.isAbsolute(dir) ? dir : import_node_path23.default.join(config.workspace, dir);
2632
+ const absoluteDir = import_node_path24.default.isAbsolute(dir) ? dir : import_node_path24.default.join(config.workspace, dir);
2538
2633
  if (import_node_fs8.default.existsSync(absoluteDir)) {
2539
2634
  if (route) {
2540
2635
  app.use(route, (0, import_serve_static.default)(absoluteDir));
@@ -2554,8 +2649,8 @@ var ServerTask = class extends BaseTask {
2554
2649
  const isGetOrHead = req.method === "GET" || req.method === "HEAD";
2555
2650
  const isHtmlNav = !req.url?.includes(".") || req.headers.accept?.includes("text/html");
2556
2651
  if (isGetOrHead && isHtmlNav) {
2557
- const indexPath = import_node_path23.default.join(config.dest.html, "index.html");
2558
- const srcIndexPath = import_node_path23.default.join(config.src.base, "index.html");
2652
+ const indexPath = import_node_path24.default.join(config.dest.html, "index.html");
2653
+ const srcIndexPath = import_node_path24.default.join(config.src.base, "index.html");
2559
2654
  const fileToServe = import_node_fs8.default.existsSync(indexPath) ? indexPath : srcIndexPath;
2560
2655
  if (import_node_fs8.default.existsSync(fileToServe)) {
2561
2656
  res.setHeader("Content-Type", "text/html; charset=utf-8");
@@ -2605,7 +2700,7 @@ var ServerTask = class extends BaseTask {
2605
2700
  };
2606
2701
 
2607
2702
  // src/tasks/static.ts
2608
- var import_node_path24 = __toESM(require("path"), 1);
2703
+ var import_node_path25 = __toESM(require("path"), 1);
2609
2704
  var import_node_fs9 = require("fs");
2610
2705
  var StaticTask = class extends BaseTask {
2611
2706
  constructor() {
@@ -2615,8 +2710,8 @@ var StaticTask = class extends BaseTask {
2615
2710
  const srcBase = config.src.base;
2616
2711
  const destBase = config.dest.base;
2617
2712
  const staticPatterns = [
2618
- import_node_path24.default.join(srcBase, "*.{ico,png,svg,json,txt,xml,webmanifest}"),
2619
- `!${import_node_path24.default.join(srcBase, "*.html")}`
2713
+ import_node_path25.default.join(srcBase, "*.{ico,png,svg,json,txt,xml,webmanifest}"),
2714
+ `!${import_node_path25.default.join(srcBase, "*.html")}`
2620
2715
  ];
2621
2716
  const extraIncludes = [
2622
2717
  ...config.extras?.includes || [],
@@ -2627,11 +2722,11 @@ var StaticTask = class extends BaseTask {
2627
2722
  ...config.assets?.excludes || []
2628
2723
  ];
2629
2724
  for (const inc of extraIncludes) {
2630
- const pattern = import_node_path24.default.isAbsolute(inc) ? inc : import_node_path24.default.join(srcBase, inc);
2725
+ const pattern = import_node_path25.default.isAbsolute(inc) ? inc : import_node_path25.default.join(srcBase, inc);
2631
2726
  staticPatterns.push(pattern);
2632
2727
  }
2633
2728
  for (const exc of extraExcludes) {
2634
- const pattern = import_node_path24.default.isAbsolute(exc) ? exc : import_node_path24.default.join(srcBase, exc);
2729
+ const pattern = import_node_path25.default.isAbsolute(exc) ? exc : import_node_path25.default.join(srcBase, exc);
2635
2730
  staticPatterns.push(`!${pattern}`);
2636
2731
  }
2637
2732
  const pipeline = Pipeline.from(staticPatterns, {
@@ -2640,38 +2735,42 @@ var StaticTask = class extends BaseTask {
2640
2735
  });
2641
2736
  const publicUrlReplacement = config.assets.virtualDir ? `/${config.assets.virtualDir}` : "";
2642
2737
  pipeline.pipe(async (file2) => {
2643
- if (file2.basename === "manifest.json" || file2.extname === ".json") {
2738
+ const isManifest = isManifestFile(file2, config);
2739
+ if (isManifest || file2.extname === ".json") {
2644
2740
  let content = file2.toString();
2645
2741
  content = content.replaceAll(PUBLIC_URL, publicUrlReplacement);
2742
+ if (isManifest) {
2743
+ content = rewriteHtmlAssetPaths(content, config);
2744
+ }
2646
2745
  file2.contents = Buffer.from(content);
2647
2746
  }
2648
2747
  return file2;
2649
2748
  });
2650
2749
  await pipeline.dest(destBase);
2651
2750
  if (config.src.img && (0, import_node_fs9.existsSync)(config.src.img)) {
2652
- const imgPipeline = Pipeline.from(import_node_path24.default.join(config.src.img, "**/*"), {
2751
+ const imgPipeline = Pipeline.from(import_node_path25.default.join(config.src.img, "**/*"), {
2653
2752
  cwd: config.workspace,
2654
2753
  base: config.src.img
2655
2754
  });
2656
2755
  await imgPipeline.dest(config.dest.img);
2657
2756
  }
2658
2757
  if (config.src.font && (0, import_node_fs9.existsSync)(config.src.font)) {
2659
- const fontPipeline = Pipeline.from(import_node_path24.default.join(config.src.font, "**/*"), {
2758
+ const fontPipeline = Pipeline.from(import_node_path25.default.join(config.src.font, "**/*"), {
2660
2759
  cwd: config.workspace,
2661
2760
  base: config.src.font
2662
2761
  });
2663
2762
  await fontPipeline.dest(config.dest.font);
2664
2763
  }
2665
2764
  if (config.src.media && (0, import_node_fs9.existsSync)(config.src.media)) {
2666
- const mediaPipeline = Pipeline.from(import_node_path24.default.join(config.src.media, "**/*"), {
2765
+ const mediaPipeline = Pipeline.from(import_node_path25.default.join(config.src.media, "**/*"), {
2667
2766
  cwd: config.workspace,
2668
2767
  base: config.src.media
2669
2768
  });
2670
2769
  await mediaPipeline.dest(config.dest.media);
2671
2770
  }
2672
- const publicDir = import_node_path24.default.join(config.workspace, "public");
2771
+ const publicDir = import_node_path25.default.join(config.workspace, "public");
2673
2772
  if ((0, import_node_fs9.existsSync)(publicDir)) {
2674
- const pubPipeline = Pipeline.from(import_node_path24.default.join(publicDir, "**/*"), {
2773
+ const pubPipeline = Pipeline.from(import_node_path25.default.join(publicDir, "**/*"), {
2675
2774
  cwd: config.workspace,
2676
2775
  base: publicDir
2677
2776
  });
@@ -2974,6 +3073,7 @@ var index_default = balm;
2974
3073
  isArray,
2975
3074
  isBoolean,
2976
3075
  isFunction,
3076
+ isManifestFile,
2977
3077
  isObject,
2978
3078
  isString,
2979
3079
  localResolve,
@@ -2981,11 +3081,15 @@ var index_default = balm;
2981
3081
  logger,
2982
3082
  resolveConfig,
2983
3083
  resolveDefaultEntry,
3084
+ rewriteCssAssetUrls,
3085
+ rewriteHtmlAssetPaths,
2984
3086
  runEsbuild,
2985
3087
  runRollup,
2986
3088
  runWebpack,
2987
3089
  setWorkspaces,
3090
+ shouldUseTargetPaths,
2988
3091
  toNamespace,
3092
+ transformCssUrl,
2989
3093
  transformHtmlmin,
2990
3094
  transformLess,
2991
3095
  transformPostcss,