balm-core 6.0.0-alpha.2 → 6.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/index.cjs +559 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -3
- package/dist/index.d.ts +42 -3
- package/dist/index.js +540 -210
- package/dist/index.js.map +1 -1
- package/package.json +38 -1
- package/src/balm.ts +0 -107
- package/src/bundler/esbuild.ts +0 -48
- package/src/bundler/index.ts +0 -3
- package/src/bundler/rollup.ts +0 -46
- package/src/bundler/webpack.ts +0 -125
- package/src/config/constants.ts +0 -12
- package/src/config/defaults.ts +0 -212
- package/src/config/index.ts +0 -112
- package/src/hooks/index.ts +0 -224
- package/src/index.ts +0 -16
- package/src/pipeline/file.ts +0 -69
- package/src/pipeline/index.ts +0 -10
- package/src/pipeline/pipeline.ts +0 -135
- package/src/pipeline/transforms/cache.ts +0 -147
- package/src/pipeline/transforms/htmlmin.ts +0 -18
- package/src/pipeline/transforms/less.ts +0 -75
- package/src/pipeline/transforms/postcss.ts +0 -43
- package/src/pipeline/transforms/rename.ts +0 -38
- package/src/pipeline/transforms/replace.ts +0 -30
- package/src/pipeline/transforms/sass.ts +0 -106
- package/src/pipeline/transforms/terser.ts +0 -20
- package/src/runner/dag.ts +0 -77
- package/src/runner/task.ts +0 -38
- package/src/shims.d.ts +0 -5
- package/src/tasks/cache.ts +0 -84
- package/src/tasks/clean.ts +0 -21
- package/src/tasks/copy.ts +0 -36
- package/src/tasks/ftp.ts +0 -90
- package/src/tasks/html.ts +0 -290
- package/src/tasks/index.ts +0 -14
- package/src/tasks/publish.ts +0 -71
- package/src/tasks/pwa.ts +0 -86
- package/src/tasks/remove.ts +0 -24
- package/src/tasks/replace.ts +0 -34
- package/src/tasks/script.ts +0 -28
- package/src/tasks/server.ts +0 -218
- package/src/tasks/static.ts +0 -77
- package/src/tasks/style.ts +0 -57
- package/src/tasks/zip.ts +0 -77
- package/src/types/index.ts +0 -225
- package/src/utilities/file.ts +0 -140
- package/src/utilities/logger.ts +0 -63
- package/src/utilities/utils.ts +0 -46
- package/src/utilities/workspace.ts +0 -38
- package/src/watcher/index.ts +0 -100
- package/tsconfig.json +0 -8
- package/tsup.config.ts +0 -12
package/dist/index.js
CHANGED
|
@@ -83,6 +83,19 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
83
83
|
js: true,
|
|
84
84
|
url: true
|
|
85
85
|
},
|
|
86
|
+
includeJsResource: [],
|
|
87
|
+
excludeUrlResource: [],
|
|
88
|
+
useEsModule: true,
|
|
89
|
+
urlLoaderOptions: {},
|
|
90
|
+
babelLoaderOptions: {},
|
|
91
|
+
htmlLoaderOptions: {},
|
|
92
|
+
postcssLoaderOptions: {},
|
|
93
|
+
sourceMap: false,
|
|
94
|
+
stats: void 0,
|
|
95
|
+
optimization: {},
|
|
96
|
+
extractAllVendors: false,
|
|
97
|
+
vendorName: "vendor",
|
|
98
|
+
extractCss: false,
|
|
86
99
|
options: {},
|
|
87
100
|
esbuildOptions: {},
|
|
88
101
|
rollupOptions: {},
|
|
@@ -121,6 +134,10 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
121
134
|
includes: [],
|
|
122
135
|
excludes: []
|
|
123
136
|
};
|
|
137
|
+
const extras = {
|
|
138
|
+
includes: [],
|
|
139
|
+
excludes: []
|
|
140
|
+
};
|
|
124
141
|
const server = {
|
|
125
142
|
host: null,
|
|
126
143
|
port: 3e3,
|
|
@@ -194,6 +211,7 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
194
211
|
scripts,
|
|
195
212
|
html,
|
|
196
213
|
assets,
|
|
214
|
+
extras,
|
|
197
215
|
server,
|
|
198
216
|
pwa,
|
|
199
217
|
ftp,
|
|
@@ -222,13 +240,18 @@ function isFunction(val) {
|
|
|
222
240
|
function isBoolean(val) {
|
|
223
241
|
return typeof val === "boolean";
|
|
224
242
|
}
|
|
243
|
+
function isPlainObject(val) {
|
|
244
|
+
if (val === null || typeof val !== "object") return false;
|
|
245
|
+
const proto = Object.getPrototypeOf(val);
|
|
246
|
+
return proto === Object.prototype || proto === null;
|
|
247
|
+
}
|
|
225
248
|
function deepMerge(target, ...sources) {
|
|
226
249
|
if (!sources.length) return target;
|
|
227
250
|
const source = sources.shift();
|
|
228
|
-
if (
|
|
251
|
+
if (isPlainObject(target) && isPlainObject(source)) {
|
|
229
252
|
for (const key in source) {
|
|
230
|
-
if (
|
|
231
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
253
|
+
if (isPlainObject(source[key])) {
|
|
254
|
+
if (!isPlainObject(target[key])) Object.assign(target, { [key]: {} });
|
|
232
255
|
deepMerge(target[key], source[key]);
|
|
233
256
|
} else if (isArray(source[key])) {
|
|
234
257
|
target[key] = [...source[key]];
|
|
@@ -638,7 +661,7 @@ var CleanTask = class extends BaseTask {
|
|
|
638
661
|
};
|
|
639
662
|
|
|
640
663
|
// src/tasks/style.ts
|
|
641
|
-
import
|
|
664
|
+
import path11 from "path";
|
|
642
665
|
|
|
643
666
|
// src/pipeline/pipeline.ts
|
|
644
667
|
import path7 from "path";
|
|
@@ -722,7 +745,10 @@ var Pipeline = class _Pipeline {
|
|
|
722
745
|
this.transforms.push(async () => {
|
|
723
746
|
const patternArr = Array.isArray(patterns) ? patterns : [patterns];
|
|
724
747
|
const posPatterns = patternArr.filter((p) => !p.startsWith("!"));
|
|
725
|
-
const ignorePatterns =
|
|
748
|
+
const ignorePatterns = [
|
|
749
|
+
"**/.DS_Store",
|
|
750
|
+
...patternArr.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
751
|
+
];
|
|
726
752
|
const fileList = [];
|
|
727
753
|
for (const p of posPatterns) {
|
|
728
754
|
let patternBase = this.base;
|
|
@@ -976,6 +1002,96 @@ function transformPostcss(options = {}) {
|
|
|
976
1002
|
};
|
|
977
1003
|
}
|
|
978
1004
|
|
|
1005
|
+
// src/pipeline/transforms/url.ts
|
|
1006
|
+
import path10 from "path";
|
|
1007
|
+
var CSS_ASSET_TYPES = ["img", "font", "media"];
|
|
1008
|
+
var HTML_ASSET_TYPES = ["css", "js", "img", "font", "media"];
|
|
1009
|
+
function escapeRegExp(value) {
|
|
1010
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1011
|
+
}
|
|
1012
|
+
function normalizeSegment(value) {
|
|
1013
|
+
return value ? value.replace(/^\/+|\/+$/g, "") : "";
|
|
1014
|
+
}
|
|
1015
|
+
function shouldUseTargetPaths(config) {
|
|
1016
|
+
return Boolean(config.env?.isProd || !config.inFrontend);
|
|
1017
|
+
}
|
|
1018
|
+
function isManifestFile(file2, config) {
|
|
1019
|
+
const manifestFilename = path10.basename(config.pwa?.manifest || "manifest.json");
|
|
1020
|
+
return file2.basename === manifestFilename || file2.extname.toLowerCase() === ".webmanifest";
|
|
1021
|
+
}
|
|
1022
|
+
function rewriteCssAssetUrls(content, config) {
|
|
1023
|
+
if (!shouldUseTargetPaths(config)) {
|
|
1024
|
+
return content;
|
|
1025
|
+
}
|
|
1026
|
+
let updated = content;
|
|
1027
|
+
for (const type of CSS_ASSET_TYPES) {
|
|
1028
|
+
const source = normalizeSegment(config.paths?.source?.[type]);
|
|
1029
|
+
const target = normalizeSegment(config.paths?.target?.[type]);
|
|
1030
|
+
if (!source || !target) continue;
|
|
1031
|
+
const sourceLeaf = source.split("/").pop();
|
|
1032
|
+
const candidates = Array.from(
|
|
1033
|
+
new Set(
|
|
1034
|
+
[source, sourceLeaf].filter(
|
|
1035
|
+
(item) => Boolean(item && item !== target)
|
|
1036
|
+
)
|
|
1037
|
+
)
|
|
1038
|
+
).sort((a, b) => b.length - a.length);
|
|
1039
|
+
if (!candidates.length) continue;
|
|
1040
|
+
const alternation = candidates.map(escapeRegExp).join("|");
|
|
1041
|
+
const relativeRegex = new RegExp(
|
|
1042
|
+
`(^|[\\s('",])((?:\\.{2}\\/)+)(?:${alternation})\\/`,
|
|
1043
|
+
"g"
|
|
1044
|
+
);
|
|
1045
|
+
updated = updated.replace(relativeRegex, `$1$2${target}/`);
|
|
1046
|
+
const rootUrlRegex = new RegExp(
|
|
1047
|
+
`(url\\(\\s*['"]?)\\/(?:${alternation})\\/`,
|
|
1048
|
+
"gi"
|
|
1049
|
+
);
|
|
1050
|
+
updated = updated.replace(rootUrlRegex, `$1/${target}/`);
|
|
1051
|
+
}
|
|
1052
|
+
return updated;
|
|
1053
|
+
}
|
|
1054
|
+
function rewriteHtmlAssetPaths(content, config) {
|
|
1055
|
+
if (!shouldUseTargetPaths(config)) {
|
|
1056
|
+
return content;
|
|
1057
|
+
}
|
|
1058
|
+
const sourceMap = /* @__PURE__ */ new Map();
|
|
1059
|
+
for (const type of HTML_ASSET_TYPES) {
|
|
1060
|
+
const source = normalizeSegment(config.paths?.source?.[type]);
|
|
1061
|
+
const target = normalizeSegment(config.paths?.target?.[type]);
|
|
1062
|
+
if (source && target && source !== target) {
|
|
1063
|
+
sourceMap.set(source, target);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
if (!sourceMap.size) {
|
|
1067
|
+
return content;
|
|
1068
|
+
}
|
|
1069
|
+
const alternation = Array.from(sourceMap.keys()).sort((a, b) => b.length - a.length).map(escapeRegExp).join("|");
|
|
1070
|
+
const virtualDir = normalizeSegment(config.assets?.virtualDir);
|
|
1071
|
+
const virtualPrefix = virtualDir ? `\\/${escapeRegExp(virtualDir)}\\/|` : "";
|
|
1072
|
+
const prefixedRegex = new RegExp(
|
|
1073
|
+
`(^|["'\`=(,\\s])(${virtualPrefix}(?:\\.{1,2}\\/)+|\\/)(${alternation})\\/`,
|
|
1074
|
+
"g"
|
|
1075
|
+
);
|
|
1076
|
+
let updated = content.replace(
|
|
1077
|
+
prefixedRegex,
|
|
1078
|
+
(_, lead, prefix, src) => `${lead}${prefix}${sourceMap.get(src)}/`
|
|
1079
|
+
);
|
|
1080
|
+
const bareQuotedRegex = new RegExp(`(["'\`=])(${alternation})\\/`, "g");
|
|
1081
|
+
updated = updated.replace(
|
|
1082
|
+
bareQuotedRegex,
|
|
1083
|
+
(_, lead, src) => `${lead}${sourceMap.get(src)}/`
|
|
1084
|
+
);
|
|
1085
|
+
return updated;
|
|
1086
|
+
}
|
|
1087
|
+
function transformCssUrl(config) {
|
|
1088
|
+
return async (file2) => {
|
|
1089
|
+
if (!/\.css$/i.test(file2.extname)) return file2;
|
|
1090
|
+
file2.contents = Buffer.from(rewriteCssAssetUrls(file2.toString(), config));
|
|
1091
|
+
return file2;
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
|
|
979
1095
|
// src/tasks/style.ts
|
|
980
1096
|
var StyleTask = class extends BaseTask {
|
|
981
1097
|
constructor() {
|
|
@@ -983,9 +1099,9 @@ var StyleTask = class extends BaseTask {
|
|
|
983
1099
|
}
|
|
984
1100
|
async run(config) {
|
|
985
1101
|
const ext = config.styles.extname;
|
|
986
|
-
const srcPattern =
|
|
1102
|
+
const srcPattern = path11.join(config.src.css, `**/*.${ext}`);
|
|
987
1103
|
const isProd = config.env.isProd;
|
|
988
|
-
const pipeline = Pipeline.from([srcPattern, `!${
|
|
1104
|
+
const pipeline = Pipeline.from([srcPattern, `!${path11.join(config.src.css, "**/_*.scss")}`, `!${path11.join(config.src.css, "**/_*.less")}`], {
|
|
989
1105
|
cwd: config.workspace,
|
|
990
1106
|
base: config.src.css
|
|
991
1107
|
});
|
|
@@ -1017,13 +1133,180 @@ var StyleTask = class extends BaseTask {
|
|
|
1017
1133
|
...config.styles.postcssLoaderOptions
|
|
1018
1134
|
})
|
|
1019
1135
|
);
|
|
1136
|
+
pipeline.pipe(transformCssUrl(config));
|
|
1020
1137
|
await pipeline.dest(config.dest.css);
|
|
1021
1138
|
}
|
|
1022
1139
|
};
|
|
1023
1140
|
|
|
1024
1141
|
// src/bundler/webpack.ts
|
|
1025
1142
|
import webpack from "webpack";
|
|
1026
|
-
import
|
|
1143
|
+
import path12 from "path";
|
|
1144
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
1145
|
+
import { createRequire } from "module";
|
|
1146
|
+
import autoprefixer2 from "autoprefixer";
|
|
1147
|
+
import postcssPresetEnv2 from "postcss-preset-env";
|
|
1148
|
+
var coreRequire = createRequire(import.meta.url);
|
|
1149
|
+
var BABEL_CONFIG_FILES = [
|
|
1150
|
+
"babel.config.js",
|
|
1151
|
+
"babel.config.cjs",
|
|
1152
|
+
"babel.config.mjs",
|
|
1153
|
+
"babel.config.json",
|
|
1154
|
+
".babelrc",
|
|
1155
|
+
".babelrc.js",
|
|
1156
|
+
".babelrc.cjs",
|
|
1157
|
+
".babelrc.json"
|
|
1158
|
+
];
|
|
1159
|
+
function resolveModule(pkgName, workspace) {
|
|
1160
|
+
try {
|
|
1161
|
+
const workspaceRequire = createRequire(path12.join(workspace, "package.json"));
|
|
1162
|
+
return workspaceRequire.resolve(pkgName);
|
|
1163
|
+
} catch {
|
|
1164
|
+
return coreRequire.resolve(pkgName);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function resolveWorkspacePaths(paths, workspace) {
|
|
1168
|
+
if (!paths || !paths.length) return [];
|
|
1169
|
+
return paths.map((p) => path12.isAbsolute(p) ? p : path12.resolve(workspace, p));
|
|
1170
|
+
}
|
|
1171
|
+
function hasBabelConfig(config) {
|
|
1172
|
+
if (config.scripts.babelLoaderOptions && Object.keys(config.scripts.babelLoaderOptions).length > 0) {
|
|
1173
|
+
return true;
|
|
1174
|
+
}
|
|
1175
|
+
for (const filename of BABEL_CONFIG_FILES) {
|
|
1176
|
+
if (existsSync2(path12.join(config.workspace, filename))) {
|
|
1177
|
+
return true;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
const pkgPath = path12.join(config.workspace, "package.json");
|
|
1181
|
+
if (existsSync2(pkgPath)) {
|
|
1182
|
+
try {
|
|
1183
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
1184
|
+
if (pkg && pkg.babel) {
|
|
1185
|
+
return true;
|
|
1186
|
+
}
|
|
1187
|
+
} catch {
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return false;
|
|
1191
|
+
}
|
|
1192
|
+
function buildDefaultRules(config, dirs, devtool) {
|
|
1193
|
+
const isProd = config.env.isProd;
|
|
1194
|
+
const scripts = config.scripts;
|
|
1195
|
+
const esModule = scripts.useEsModule ?? true;
|
|
1196
|
+
const defaults = {
|
|
1197
|
+
html: true,
|
|
1198
|
+
css: true,
|
|
1199
|
+
js: true,
|
|
1200
|
+
url: true,
|
|
1201
|
+
...scripts.defaultLoaders || {}
|
|
1202
|
+
};
|
|
1203
|
+
const rules = [];
|
|
1204
|
+
if (defaults.html) {
|
|
1205
|
+
rules.push({
|
|
1206
|
+
test: /\.html$/i,
|
|
1207
|
+
exclude: /\.vue\.html$/i,
|
|
1208
|
+
loader: resolveModule("html-loader", config.workspace),
|
|
1209
|
+
options: {
|
|
1210
|
+
minimize: {
|
|
1211
|
+
removeAttributeQuotes: false
|
|
1212
|
+
},
|
|
1213
|
+
esModule,
|
|
1214
|
+
...scripts.htmlLoaderOptions || {}
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
if (defaults.css) {
|
|
1219
|
+
const cssSourceMap = Boolean(devtool);
|
|
1220
|
+
const MiniCssExtractPlugin = coreRequire("mini-css-extract-plugin");
|
|
1221
|
+
const styleLoader = isProd && scripts.extractCss ? {
|
|
1222
|
+
loader: MiniCssExtractPlugin.loader,
|
|
1223
|
+
options: { esModule }
|
|
1224
|
+
} : {
|
|
1225
|
+
loader: resolveModule("style-loader", config.workspace),
|
|
1226
|
+
options: { esModule }
|
|
1227
|
+
};
|
|
1228
|
+
const postcssPlugins = [
|
|
1229
|
+
...config.styles.postcssPlugins || [],
|
|
1230
|
+
autoprefixer2(),
|
|
1231
|
+
postcssPresetEnv2()
|
|
1232
|
+
];
|
|
1233
|
+
const createCssUse = (isModule) => [
|
|
1234
|
+
styleLoader,
|
|
1235
|
+
{
|
|
1236
|
+
loader: resolveModule("css-loader", config.workspace),
|
|
1237
|
+
options: {
|
|
1238
|
+
importLoaders: 1,
|
|
1239
|
+
sourceMap: cssSourceMap,
|
|
1240
|
+
modules: isModule ? { auto: true } : { mode: "icss" },
|
|
1241
|
+
esModule
|
|
1242
|
+
}
|
|
1243
|
+
},
|
|
1244
|
+
{
|
|
1245
|
+
loader: resolveModule("postcss-loader", config.workspace),
|
|
1246
|
+
options: {
|
|
1247
|
+
postcssOptions: {
|
|
1248
|
+
plugins: postcssPlugins
|
|
1249
|
+
},
|
|
1250
|
+
sourceMap: cssSourceMap,
|
|
1251
|
+
...scripts.postcssLoaderOptions || {}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
];
|
|
1255
|
+
rules.push(
|
|
1256
|
+
{
|
|
1257
|
+
test: /\.css$/,
|
|
1258
|
+
exclude: /\.module\.css$/,
|
|
1259
|
+
use: createCssUse(false),
|
|
1260
|
+
sideEffects: true
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
test: /\.module\.css$/,
|
|
1264
|
+
use: createCssUse(true)
|
|
1265
|
+
}
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
if (defaults.js && hasBabelConfig(config)) {
|
|
1269
|
+
const jsIncludes = [
|
|
1270
|
+
config.src.js,
|
|
1271
|
+
...resolveWorkspacePaths(scripts.includeJsResource, config.workspace)
|
|
1272
|
+
];
|
|
1273
|
+
rules.push({
|
|
1274
|
+
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
|
1275
|
+
include: jsIncludes,
|
|
1276
|
+
loader: resolveModule("babel-loader", config.workspace),
|
|
1277
|
+
options: {
|
|
1278
|
+
cwd: config.workspace,
|
|
1279
|
+
...scripts.babelLoaderOptions || {}
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
if (defaults.url) {
|
|
1284
|
+
const rawLimit = scripts.urlLoaderOptions?.limit ?? (process.env.IMAGE_INLINE_SIZE_LIMIT ? parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT, 10) : 1e4);
|
|
1285
|
+
const maxSize = typeof rawLimit === "number" && rawLimit > 0 ? rawLimit : 0;
|
|
1286
|
+
const excludeUrl = resolveWorkspacePaths(scripts.excludeUrlResource, config.workspace);
|
|
1287
|
+
const createAssetRule = (test, targetDir, exclude) => ({
|
|
1288
|
+
test,
|
|
1289
|
+
...exclude && exclude.length ? { exclude } : {},
|
|
1290
|
+
type: maxSize > 0 ? "asset" : "asset/resource",
|
|
1291
|
+
...maxSize > 0 ? {
|
|
1292
|
+
parser: {
|
|
1293
|
+
dataUrlCondition: {
|
|
1294
|
+
maxSize
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
} : {},
|
|
1298
|
+
generator: {
|
|
1299
|
+
filename: `${targetDir}/[name].[hash:8][ext]`
|
|
1300
|
+
}
|
|
1301
|
+
});
|
|
1302
|
+
rules.push(
|
|
1303
|
+
createAssetRule(/\.(bmp|gif|jpe?g|png|svg|webp)(\?.*)?$/i, dirs.imgDir, excludeUrl),
|
|
1304
|
+
createAssetRule(/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i, dirs.mediaDir),
|
|
1305
|
+
createAssetRule(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i, dirs.fontDir)
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
return rules;
|
|
1309
|
+
}
|
|
1027
1310
|
async function runWebpack(config, customOptions = {}) {
|
|
1028
1311
|
const isProd = config.env.isProd;
|
|
1029
1312
|
let entry = customOptions.entry || config.scripts.entry;
|
|
@@ -1032,10 +1315,49 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1032
1315
|
}
|
|
1033
1316
|
const rawOutputPath = customOptions.output?.path;
|
|
1034
1317
|
const isCustomOutput = Boolean(rawOutputPath);
|
|
1035
|
-
const outputPath = isCustomOutput ?
|
|
1318
|
+
const outputPath = isCustomOutput ? path12.isAbsolute(rawOutputPath) ? rawOutputPath : path12.resolve(config.workspace, rawOutputPath) : config.dest.base;
|
|
1036
1319
|
const jsDir = isCustomOutput ? "" : isProd ? config.paths.target.js : config.paths.tmp.js;
|
|
1037
1320
|
const imgDir = isProd ? config.paths.target.img : config.paths.tmp.img;
|
|
1038
1321
|
const fontDir = isProd ? config.paths.target.font : config.paths.tmp.font;
|
|
1322
|
+
const mediaDir = isProd ? config.paths.target.media : config.paths.tmp.media;
|
|
1323
|
+
const devtool = config.scripts.sourceMap ? config.scripts.sourceMap === true ? isProd ? "source-map" : "eval-cheap-module-source-map" : config.scripts.sourceMap : isProd ? false : "eval-cheap-module-source-map";
|
|
1324
|
+
const libraryConfig = config.scripts.library ? typeof config.scripts.library === "string" && config.scripts.libraryTarget && config.scripts.libraryTarget !== "var" ? { name: config.scripts.library, type: config.scripts.libraryTarget } : config.scripts.library : void 0;
|
|
1325
|
+
const defaultRules = buildDefaultRules(config, { imgDir, fontDir, mediaDir }, devtool);
|
|
1326
|
+
const plugins = [...config.scripts.plugins || []];
|
|
1327
|
+
if (isProd && config.scripts.extractCss) {
|
|
1328
|
+
const MiniCssExtractPlugin = coreRequire("mini-css-extract-plugin");
|
|
1329
|
+
const cssDir = config.paths.target.css;
|
|
1330
|
+
const cssFilename = config.assets.cache ? `${cssDir}/async/[name].[contenthash:8].css` : `${cssDir}/async/[name].css`;
|
|
1331
|
+
plugins.push(
|
|
1332
|
+
new MiniCssExtractPlugin({
|
|
1333
|
+
filename: cssFilename,
|
|
1334
|
+
chunkFilename: cssFilename
|
|
1335
|
+
})
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
const vendorName = config.scripts.vendorName || "vendor";
|
|
1339
|
+
const defaultOptimization = {
|
|
1340
|
+
minimize: isProd || config.scripts.minify
|
|
1341
|
+
};
|
|
1342
|
+
if (config.scripts.extractAllVendors) {
|
|
1343
|
+
const vendorFilename = isCustomOutput ? `${vendorName}.js` : isProd && config.assets.cache ? `${jsDir}/${vendorName}.[contenthash:8].js` : `${jsDir}/${vendorName}.js`;
|
|
1344
|
+
defaultOptimization.splitChunks = {
|
|
1345
|
+
cacheGroups: {
|
|
1346
|
+
vendors: {
|
|
1347
|
+
name: vendorName,
|
|
1348
|
+
chunks: "initial",
|
|
1349
|
+
test: /[\\/](node_modules|bower_components)[\\/]/,
|
|
1350
|
+
filename: vendorFilename
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
const optimization = deepMerge(
|
|
1356
|
+
{},
|
|
1357
|
+
defaultOptimization,
|
|
1358
|
+
config.scripts.optimization || {}
|
|
1359
|
+
);
|
|
1360
|
+
const externals = config.scripts.externals && (typeof config.scripts.externals !== "string" || config.scripts.externals.length > 0) ? config.scripts.externals : void 0;
|
|
1039
1361
|
const defaultWebpackConfig = {
|
|
1040
1362
|
mode: isProd ? "production" : "development",
|
|
1041
1363
|
context: config.workspace,
|
|
@@ -1045,14 +1367,13 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1045
1367
|
filename: isCustomOutput ? "[name].js" : isProd && config.assets.cache ? `${jsDir}/[name].[contenthash:8].js` : `${jsDir}/[name].js`,
|
|
1046
1368
|
chunkFilename: isCustomOutput ? "chunk/[name].js" : isProd && config.assets.cache ? `${jsDir}/chunk/[name].[chunkhash:8].js` : `${jsDir}/chunk/[name].js`,
|
|
1047
1369
|
publicPath: config.assets.virtualDir ? `/${config.assets.virtualDir}/` : "/",
|
|
1048
|
-
...
|
|
1370
|
+
...libraryConfig ? { library: libraryConfig } : {}
|
|
1049
1371
|
},
|
|
1050
1372
|
target: config.scripts.target || "web",
|
|
1051
|
-
externals:
|
|
1052
|
-
plugins
|
|
1053
|
-
...config.scripts.plugins || []
|
|
1054
|
-
],
|
|
1373
|
+
...externals !== void 0 ? { externals } : {},
|
|
1374
|
+
plugins,
|
|
1055
1375
|
resolve: {
|
|
1376
|
+
modules: ["node_modules", config.src.base],
|
|
1056
1377
|
extensions: [
|
|
1057
1378
|
".wasm",
|
|
1058
1379
|
".mjs",
|
|
@@ -1070,28 +1391,11 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1070
1391
|
}
|
|
1071
1392
|
},
|
|
1072
1393
|
module: {
|
|
1073
|
-
rules: [
|
|
1074
|
-
...config.scripts.loaders || [],
|
|
1075
|
-
{
|
|
1076
|
-
test: /\.(png|jpe?g|gif|svg|webp)$/i,
|
|
1077
|
-
type: "asset/resource",
|
|
1078
|
-
generator: {
|
|
1079
|
-
filename: `${imgDir}/[name].[hash:8][ext]`
|
|
1080
|
-
}
|
|
1081
|
-
},
|
|
1082
|
-
{
|
|
1083
|
-
test: /\.(woff2?|eot|ttf|otf)$/i,
|
|
1084
|
-
type: "asset/resource",
|
|
1085
|
-
generator: {
|
|
1086
|
-
filename: `${fontDir}/[name].[hash:8][ext]`
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
]
|
|
1090
|
-
},
|
|
1091
|
-
optimization: {
|
|
1092
|
-
minimize: isProd || config.scripts.minify
|
|
1394
|
+
rules: [...defaultRules, ...config.scripts.loaders || []]
|
|
1093
1395
|
},
|
|
1094
|
-
|
|
1396
|
+
optimization,
|
|
1397
|
+
...config.scripts.stats !== void 0 ? { stats: config.scripts.stats } : {},
|
|
1398
|
+
devtool
|
|
1095
1399
|
};
|
|
1096
1400
|
const webpackConfig = {
|
|
1097
1401
|
...defaultWebpackConfig,
|
|
@@ -1109,14 +1413,21 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1109
1413
|
compiler.run((err, stats) => {
|
|
1110
1414
|
if (err) {
|
|
1111
1415
|
logger.error("webpack", err.stack || err);
|
|
1112
|
-
|
|
1416
|
+
compiler.close(() => reject(err));
|
|
1417
|
+
return;
|
|
1113
1418
|
}
|
|
1114
1419
|
if (stats?.hasErrors()) {
|
|
1115
1420
|
const info = stats.toJson();
|
|
1116
1421
|
logger.error("webpack", info.errors?.map((e) => e.message).join("\n"));
|
|
1117
|
-
|
|
1422
|
+
compiler.close(() => reject(new Error("Webpack compilation errors")));
|
|
1423
|
+
return;
|
|
1118
1424
|
}
|
|
1119
|
-
|
|
1425
|
+
compiler.close((closeErr) => {
|
|
1426
|
+
if (closeErr) {
|
|
1427
|
+
return reject(closeErr);
|
|
1428
|
+
}
|
|
1429
|
+
resolve(stats);
|
|
1430
|
+
});
|
|
1120
1431
|
});
|
|
1121
1432
|
});
|
|
1122
1433
|
}
|
|
@@ -1209,8 +1520,8 @@ var ScriptTask = class extends BaseTask {
|
|
|
1209
1520
|
};
|
|
1210
1521
|
|
|
1211
1522
|
// src/tasks/html.ts
|
|
1212
|
-
import
|
|
1213
|
-
import { existsSync as
|
|
1523
|
+
import path13 from "path";
|
|
1524
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1214
1525
|
import fg3 from "fast-glob";
|
|
1215
1526
|
|
|
1216
1527
|
// src/pipeline/transforms/htmlmin.ts
|
|
@@ -1242,10 +1553,18 @@ function transformReplace(options, replacement) {
|
|
|
1242
1553
|
return async (file2) => {
|
|
1243
1554
|
let content = file2.toString();
|
|
1244
1555
|
for (const rule of rules) {
|
|
1245
|
-
if (typeof rule.
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1556
|
+
if (typeof rule.substr === "string") {
|
|
1557
|
+
if (typeof rule.replacement === "function") {
|
|
1558
|
+
content = content.replaceAll(rule.substr, rule.replacement);
|
|
1559
|
+
} else {
|
|
1560
|
+
content = content.replaceAll(rule.substr, rule.replacement);
|
|
1561
|
+
}
|
|
1562
|
+
} else if (rule.substr instanceof RegExp) {
|
|
1563
|
+
if (typeof rule.replacement === "function") {
|
|
1564
|
+
content = content.replace(rule.substr, rule.replacement);
|
|
1565
|
+
} else {
|
|
1566
|
+
content = content.replace(rule.substr, rule.replacement);
|
|
1567
|
+
}
|
|
1249
1568
|
}
|
|
1250
1569
|
}
|
|
1251
1570
|
file2.contents = Buffer.from(content);
|
|
@@ -1291,17 +1610,17 @@ var HtmlTask = class extends BaseTask {
|
|
|
1291
1610
|
const customTemplate = config.scripts.htmlPluginOptions?.template;
|
|
1292
1611
|
let pipeline;
|
|
1293
1612
|
if (customTemplate) {
|
|
1294
|
-
const templatePath =
|
|
1613
|
+
const templatePath = path13.isAbsolute(customTemplate) ? customTemplate : path13.join(config.workspace, customTemplate);
|
|
1295
1614
|
pipeline = Pipeline.from(templatePath, {
|
|
1296
1615
|
cwd: config.workspace,
|
|
1297
|
-
base:
|
|
1616
|
+
base: path13.dirname(templatePath)
|
|
1298
1617
|
});
|
|
1299
1618
|
} else {
|
|
1300
1619
|
const templateDir = config.scripts.injectHtml ? config.src.base : config.src.html;
|
|
1301
|
-
const patterns = [
|
|
1620
|
+
const patterns = [path13.join(templateDir, "*.html")];
|
|
1302
1621
|
if (config.pwa.manifest) {
|
|
1303
|
-
const manifestPattern =
|
|
1304
|
-
if (
|
|
1622
|
+
const manifestPattern = path13.join(templateDir, config.pwa.manifest);
|
|
1623
|
+
if (existsSync3(path13.isAbsolute(manifestPattern) ? manifestPattern : path13.join(config.workspace, manifestPattern))) {
|
|
1305
1624
|
patterns.push(manifestPattern);
|
|
1306
1625
|
}
|
|
1307
1626
|
}
|
|
@@ -1318,67 +1637,10 @@ var HtmlTask = class extends BaseTask {
|
|
|
1318
1637
|
return file2;
|
|
1319
1638
|
});
|
|
1320
1639
|
}
|
|
1321
|
-
if (config
|
|
1640
|
+
if (shouldUseTargetPaths(config)) {
|
|
1322
1641
|
pipeline.pipe(async (file2) => {
|
|
1323
|
-
if (/\.html$/i.test(file2.extname)) {
|
|
1324
|
-
|
|
1325
|
-
if (config.paths.source.css && config.paths.target.css && config.paths.source.css !== config.paths.target.css) {
|
|
1326
|
-
content = content.replaceAll(
|
|
1327
|
-
`/${config.paths.source.css}/`,
|
|
1328
|
-
`/${config.paths.target.css}/`
|
|
1329
|
-
);
|
|
1330
|
-
content = content.replaceAll(
|
|
1331
|
-
`"${config.paths.source.css}/`,
|
|
1332
|
-
`"${config.paths.target.css}/`
|
|
1333
|
-
);
|
|
1334
|
-
content = content.replaceAll(
|
|
1335
|
-
`'${config.paths.source.css}/`,
|
|
1336
|
-
`'${config.paths.target.css}/`
|
|
1337
|
-
);
|
|
1338
|
-
}
|
|
1339
|
-
if (config.paths.source.js && config.paths.target.js && config.paths.source.js !== config.paths.target.js) {
|
|
1340
|
-
content = content.replaceAll(
|
|
1341
|
-
`/${config.paths.source.js}/`,
|
|
1342
|
-
`/${config.paths.target.js}/`
|
|
1343
|
-
);
|
|
1344
|
-
content = content.replaceAll(
|
|
1345
|
-
`"${config.paths.source.js}/`,
|
|
1346
|
-
`"${config.paths.target.js}/`
|
|
1347
|
-
);
|
|
1348
|
-
content = content.replaceAll(
|
|
1349
|
-
`'${config.paths.source.js}/`,
|
|
1350
|
-
`'${config.paths.target.js}/`
|
|
1351
|
-
);
|
|
1352
|
-
}
|
|
1353
|
-
if (config.paths.source.img && config.paths.target.img && config.paths.source.img !== config.paths.target.img) {
|
|
1354
|
-
content = content.replaceAll(
|
|
1355
|
-
`/${config.paths.source.img}/`,
|
|
1356
|
-
`/${config.paths.target.img}/`
|
|
1357
|
-
);
|
|
1358
|
-
content = content.replaceAll(
|
|
1359
|
-
`"${config.paths.source.img}/`,
|
|
1360
|
-
`"${config.paths.target.img}/`
|
|
1361
|
-
);
|
|
1362
|
-
content = content.replaceAll(
|
|
1363
|
-
`'${config.paths.source.img}/`,
|
|
1364
|
-
`'${config.paths.target.img}/`
|
|
1365
|
-
);
|
|
1366
|
-
}
|
|
1367
|
-
if (config.paths.source.font && config.paths.target.font && config.paths.source.font !== config.paths.target.font) {
|
|
1368
|
-
content = content.replaceAll(
|
|
1369
|
-
`/${config.paths.source.font}/`,
|
|
1370
|
-
`/${config.paths.target.font}/`
|
|
1371
|
-
);
|
|
1372
|
-
content = content.replaceAll(
|
|
1373
|
-
`"${config.paths.source.font}/`,
|
|
1374
|
-
`"${config.paths.target.font}/`
|
|
1375
|
-
);
|
|
1376
|
-
content = content.replaceAll(
|
|
1377
|
-
`'${config.paths.source.font}/`,
|
|
1378
|
-
`'${config.paths.target.font}/`
|
|
1379
|
-
);
|
|
1380
|
-
}
|
|
1381
|
-
file2.contents = Buffer.from(content);
|
|
1642
|
+
if (/\.html$/i.test(file2.extname) || isManifestFile(file2, config)) {
|
|
1643
|
+
file2.contents = Buffer.from(rewriteHtmlAssetPaths(file2.toString(), config));
|
|
1382
1644
|
}
|
|
1383
1645
|
return file2;
|
|
1384
1646
|
});
|
|
@@ -1387,7 +1649,9 @@ var HtmlTask = class extends BaseTask {
|
|
|
1387
1649
|
pipeline.pipe(async (file2) => {
|
|
1388
1650
|
if (/\.html$/i.test(file2.extname)) {
|
|
1389
1651
|
let content = file2.toString();
|
|
1390
|
-
const
|
|
1652
|
+
const entryNames = typeof config.scripts.entry === "object" && !Array.isArray(config.scripts.entry) ? Object.keys(config.scripts.entry) : ["main"];
|
|
1653
|
+
const vendorName = config.scripts.vendorName || "vendor";
|
|
1654
|
+
const entries = config.scripts.extractAllVendors ? [vendorName, ...entryNames] : entryNames;
|
|
1391
1655
|
const jsDir = config.env.isProd ? config.paths.target.js : config.paths.tmp.js;
|
|
1392
1656
|
const jsPathPrefix = config.assets.virtualDir ? `/${config.assets.virtualDir}/${jsDir}` : `/${jsDir}`;
|
|
1393
1657
|
const destJsFolder = config.dest.js;
|
|
@@ -1397,18 +1661,24 @@ var HtmlTask = class extends BaseTask {
|
|
|
1397
1661
|
)
|
|
1398
1662
|
).map((entryName) => {
|
|
1399
1663
|
let actualFilename = `${entryName}.js`;
|
|
1664
|
+
const hasUnhashed = existsSync3(path13.join(destJsFolder, actualFilename));
|
|
1665
|
+
let found = hasUnhashed;
|
|
1400
1666
|
try {
|
|
1401
1667
|
const matched = fg3.sync(`${entryName}.*.js`, { cwd: destJsFolder });
|
|
1402
1668
|
if (matched.length) {
|
|
1403
1669
|
const valid = matched.find((f) => !f.endsWith(".map") && !f.endsWith(".txt"));
|
|
1404
1670
|
if (valid) {
|
|
1405
1671
|
actualFilename = valid;
|
|
1672
|
+
found = true;
|
|
1406
1673
|
}
|
|
1407
1674
|
}
|
|
1408
1675
|
} catch {
|
|
1409
1676
|
}
|
|
1677
|
+
if (entryName === vendorName && config.scripts.extractAllVendors && !found) {
|
|
1678
|
+
return "";
|
|
1679
|
+
}
|
|
1410
1680
|
return `<script defer src="${jsPathPrefix}/${actualFilename}"></script>`;
|
|
1411
|
-
}).join("\n");
|
|
1681
|
+
}).filter(Boolean).join("\n");
|
|
1412
1682
|
if (scriptTags) {
|
|
1413
1683
|
if (content.includes("</body>")) {
|
|
1414
1684
|
content = content.replace("</body>", `${scriptTags}
|
|
@@ -1490,36 +1760,36 @@ ${LIVE_RELOAD_SCRIPT}`;
|
|
|
1490
1760
|
};
|
|
1491
1761
|
|
|
1492
1762
|
// src/tasks/copy.ts
|
|
1493
|
-
import
|
|
1763
|
+
import path15 from "path";
|
|
1494
1764
|
|
|
1495
1765
|
// src/pipeline/transforms/rename.ts
|
|
1496
|
-
import
|
|
1766
|
+
import path14 from "path";
|
|
1497
1767
|
function transformRename(options = {}) {
|
|
1498
1768
|
return async (file2) => {
|
|
1499
1769
|
if (typeof options === "string") {
|
|
1500
|
-
file2.path =
|
|
1770
|
+
file2.path = path14.resolve(path14.dirname(file2.path), options);
|
|
1501
1771
|
return file2;
|
|
1502
1772
|
}
|
|
1503
1773
|
if (typeof options === "function") {
|
|
1504
1774
|
const parsed = {
|
|
1505
|
-
dirname:
|
|
1775
|
+
dirname: path14.dirname(file2.path),
|
|
1506
1776
|
basename: file2.stem,
|
|
1507
1777
|
extname: file2.extname
|
|
1508
1778
|
};
|
|
1509
1779
|
const result = options(parsed);
|
|
1510
1780
|
if (result) {
|
|
1511
|
-
if (result.dirname) file2.path =
|
|
1781
|
+
if (result.dirname) file2.path = path14.join(result.dirname, path14.basename(file2.path));
|
|
1512
1782
|
if (result.basename) file2.stem = result.basename;
|
|
1513
1783
|
if (result.extname) file2.extname = result.extname;
|
|
1514
1784
|
}
|
|
1515
1785
|
return file2;
|
|
1516
1786
|
}
|
|
1517
1787
|
const { dirname, prefix = "", basename, suffix = "", extname } = options;
|
|
1518
|
-
const currentDir = dirname ?
|
|
1788
|
+
const currentDir = dirname ? path14.resolve(file2.cwd, dirname) : path14.dirname(file2.path);
|
|
1519
1789
|
const base = basename !== void 0 ? basename : file2.stem;
|
|
1520
1790
|
const ext = extname !== void 0 ? extname : file2.extname;
|
|
1521
1791
|
const dotExt = ext ? ext.startsWith(".") ? ext : `.${ext}` : "";
|
|
1522
|
-
file2.path =
|
|
1792
|
+
file2.path = path14.join(currentDir, `${prefix}${base}${suffix}${dotExt}`);
|
|
1523
1793
|
return file2;
|
|
1524
1794
|
};
|
|
1525
1795
|
}
|
|
@@ -1538,13 +1808,13 @@ var CopyTask = class extends BaseTask {
|
|
|
1538
1808
|
if (this.options.rename) {
|
|
1539
1809
|
pipeline.pipe(transformRename(this.options.rename));
|
|
1540
1810
|
}
|
|
1541
|
-
const outDir =
|
|
1811
|
+
const outDir = path15.isAbsolute(this.options.output) ? this.options.output : path15.join(config.workspace, this.options.output);
|
|
1542
1812
|
await pipeline.dest(outDir);
|
|
1543
1813
|
}
|
|
1544
1814
|
};
|
|
1545
1815
|
|
|
1546
1816
|
// src/tasks/remove.ts
|
|
1547
|
-
import
|
|
1817
|
+
import path16 from "path";
|
|
1548
1818
|
var RemoveTask = class extends BaseTask {
|
|
1549
1819
|
target;
|
|
1550
1820
|
constructor(target) {
|
|
@@ -1554,7 +1824,7 @@ var RemoveTask = class extends BaseTask {
|
|
|
1554
1824
|
async run(config) {
|
|
1555
1825
|
const targets = Array.isArray(this.target) ? this.target : [this.target];
|
|
1556
1826
|
const resolvedTargets = targets.map(
|
|
1557
|
-
(t) =>
|
|
1827
|
+
(t) => path16.isAbsolute(t) ? t : path16.join(config.workspace, t)
|
|
1558
1828
|
);
|
|
1559
1829
|
const deleted = await file.remove(resolvedTargets);
|
|
1560
1830
|
logger.warn("remove", `Removed: ${deleted.join(", ")}`);
|
|
@@ -1562,7 +1832,7 @@ var RemoveTask = class extends BaseTask {
|
|
|
1562
1832
|
};
|
|
1563
1833
|
|
|
1564
1834
|
// src/tasks/replace.ts
|
|
1565
|
-
import
|
|
1835
|
+
import path17 from "path";
|
|
1566
1836
|
var ReplaceTask = class extends BaseTask {
|
|
1567
1837
|
taskOptions;
|
|
1568
1838
|
constructor(taskOptions) {
|
|
@@ -1574,7 +1844,7 @@ var ReplaceTask = class extends BaseTask {
|
|
|
1574
1844
|
cwd: config.workspace
|
|
1575
1845
|
});
|
|
1576
1846
|
pipeline.pipe(transformReplace(this.taskOptions.options));
|
|
1577
|
-
const outDir =
|
|
1847
|
+
const outDir = path17.isAbsolute(this.taskOptions.output) ? this.taskOptions.output : path17.join(config.workspace, this.taskOptions.output);
|
|
1578
1848
|
await pipeline.dest(outDir);
|
|
1579
1849
|
}
|
|
1580
1850
|
};
|
|
@@ -1584,12 +1854,12 @@ import fg4 from "fast-glob";
|
|
|
1584
1854
|
import fs4 from "fs/promises";
|
|
1585
1855
|
|
|
1586
1856
|
// src/pipeline/transforms/cache.ts
|
|
1587
|
-
import
|
|
1857
|
+
import path18 from "path";
|
|
1588
1858
|
import picomatch from "picomatch";
|
|
1589
1859
|
function matchesAny(filePath, rules) {
|
|
1590
1860
|
if (!rules || !rules.length) return false;
|
|
1591
1861
|
const normalized = filePath.replace(/\\/g, "/");
|
|
1592
|
-
const baseName =
|
|
1862
|
+
const baseName = path18.basename(normalized);
|
|
1593
1863
|
for (const rawRule of rules) {
|
|
1594
1864
|
if (typeof rawRule === "string") {
|
|
1595
1865
|
const rule = rawRule.replace(/\\/g, "/");
|
|
@@ -1643,9 +1913,9 @@ var AssetRevisioner = class {
|
|
|
1643
1913
|
const shouldRename = !alreadyHashed && !matchesAny(file2.path, this.options.dontRenameFile) && !matchesAny(file2.relative, this.options.dontRenameFile);
|
|
1644
1914
|
if (shouldRename) {
|
|
1645
1915
|
const fileHash = file.hash(file2.contents, hashLength);
|
|
1646
|
-
const dir =
|
|
1916
|
+
const dir = path18.dirname(file2.path);
|
|
1647
1917
|
const newFilename = `${file2.stem}.${fileHash}${file2.extname}`;
|
|
1648
|
-
file2.path =
|
|
1918
|
+
file2.path = path18.join(dir, newFilename);
|
|
1649
1919
|
}
|
|
1650
1920
|
if (alreadyHashed) {
|
|
1651
1921
|
const unhashedRelative = file2.relative.replace(/\.[a-f0-9]{8}(\.[^.]+)$/i, "$1");
|
|
@@ -1661,8 +1931,8 @@ var AssetRevisioner = class {
|
|
|
1661
1931
|
let content = file2.toString();
|
|
1662
1932
|
for (const [orig, reved] of manifestEntries) {
|
|
1663
1933
|
content = content.replaceAll(orig, reved);
|
|
1664
|
-
const origBase =
|
|
1665
|
-
const revedBase =
|
|
1934
|
+
const origBase = path18.basename(orig);
|
|
1935
|
+
const revedBase = path18.basename(reved);
|
|
1666
1936
|
const escapedBase = origBase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1667
1937
|
const baseRegex = new RegExp(`${escapedBase}(?![a-zA-Z0-9_])`, "g");
|
|
1668
1938
|
content = content.replace(baseRegex, revedBase);
|
|
@@ -1675,7 +1945,7 @@ var AssetRevisioner = class {
|
|
|
1675
1945
|
const manifestFile = new VirtualFile({
|
|
1676
1946
|
cwd: files[0]?.cwd || process.cwd(),
|
|
1677
1947
|
base: firstBase,
|
|
1678
|
-
path:
|
|
1948
|
+
path: path18.join(firstBase, manifestName),
|
|
1679
1949
|
contents: JSON.stringify(this.manifest, null, 2)
|
|
1680
1950
|
});
|
|
1681
1951
|
outputFiles.push(manifestFile);
|
|
@@ -1751,7 +2021,7 @@ var CacheTask = class extends BaseTask {
|
|
|
1751
2021
|
};
|
|
1752
2022
|
|
|
1753
2023
|
// src/tasks/publish.ts
|
|
1754
|
-
import
|
|
2024
|
+
import path19 from "path";
|
|
1755
2025
|
var PublishTask = class extends BaseTask {
|
|
1756
2026
|
options;
|
|
1757
2027
|
constructor(options = {}) {
|
|
@@ -1772,17 +2042,17 @@ var PublishTask = class extends BaseTask {
|
|
|
1772
2042
|
await this.publishItem(config, input, output, renameOptions);
|
|
1773
2043
|
} else {
|
|
1774
2044
|
const srcDir = config.dest.base;
|
|
1775
|
-
const targetDir = config.assets.static ||
|
|
2045
|
+
const targetDir = config.assets.static || path19.join(config.assets.root, config.assets.mainDir);
|
|
1776
2046
|
const pipeline = Pipeline.from(["**/*"], {
|
|
1777
2047
|
cwd: srcDir,
|
|
1778
2048
|
base: srcDir
|
|
1779
2049
|
});
|
|
1780
|
-
await pipeline.dest(
|
|
2050
|
+
await pipeline.dest(path19.resolve(config.workspace, targetDir));
|
|
1781
2051
|
}
|
|
1782
2052
|
}
|
|
1783
2053
|
async publishItem(config, input, output, rename) {
|
|
1784
|
-
const srcPath =
|
|
1785
|
-
const destDir =
|
|
2054
|
+
const srcPath = path19.isAbsolute(input) ? input : path19.join(config.dest.base, input);
|
|
2055
|
+
const destDir = path19.isAbsolute(output) ? output : path19.join(config.workspace, config.assets.root, output);
|
|
1786
2056
|
const pipeline = Pipeline.from(srcPath, {
|
|
1787
2057
|
cwd: config.dest.base
|
|
1788
2058
|
});
|
|
@@ -1794,10 +2064,10 @@ var PublishTask = class extends BaseTask {
|
|
|
1794
2064
|
};
|
|
1795
2065
|
|
|
1796
2066
|
// src/tasks/pwa.ts
|
|
1797
|
-
import
|
|
2067
|
+
import path20 from "path";
|
|
1798
2068
|
import fs5 from "fs/promises";
|
|
1799
|
-
import { existsSync as
|
|
1800
|
-
import { createRequire } from "module";
|
|
2069
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2070
|
+
import { createRequire as createRequire2 } from "module";
|
|
1801
2071
|
import { generateSW, injectManifest } from "workbox-build";
|
|
1802
2072
|
var PwaTask = class extends BaseTask {
|
|
1803
2073
|
options;
|
|
@@ -1807,12 +2077,12 @@ var PwaTask = class extends BaseTask {
|
|
|
1807
2077
|
}
|
|
1808
2078
|
async run(config) {
|
|
1809
2079
|
const globDirectory = config.dest.base;
|
|
1810
|
-
const swDest =
|
|
1811
|
-
const swSrc =
|
|
1812
|
-
const require2 =
|
|
2080
|
+
const swDest = path20.join(globDirectory, config.pwa.swDestFilename);
|
|
2081
|
+
const swSrc = path20.join(config.src.base, config.pwa.swSrcFilename);
|
|
2082
|
+
const require2 = createRequire2(import.meta.url);
|
|
1813
2083
|
const candidatePaths = [
|
|
1814
|
-
|
|
1815
|
-
|
|
2084
|
+
path20.join(config.workspace, "node_modules/workbox-sw/build/workbox-sw.js"),
|
|
2085
|
+
path20.join(config.workspace, "node_modules/workbox-sw/controllers/WorkboxSW.mjs")
|
|
1816
2086
|
];
|
|
1817
2087
|
try {
|
|
1818
2088
|
const resolved = require2.resolve("workbox-sw/build/workbox-sw.js");
|
|
@@ -1821,12 +2091,12 @@ var PwaTask = class extends BaseTask {
|
|
|
1821
2091
|
}
|
|
1822
2092
|
try {
|
|
1823
2093
|
const resolvedPkg = require2.resolve("workbox-sw");
|
|
1824
|
-
candidatePaths.push(
|
|
2094
|
+
candidatePaths.push(path20.join(path20.dirname(resolvedPkg), "build/workbox-sw.js"));
|
|
1825
2095
|
} catch {
|
|
1826
2096
|
}
|
|
1827
2097
|
for (const p of candidatePaths) {
|
|
1828
|
-
if (
|
|
1829
|
-
const destFile =
|
|
2098
|
+
if (existsSync4(p)) {
|
|
2099
|
+
const destFile = path20.join(globDirectory, "workbox-sw.js");
|
|
1830
2100
|
await fs5.copyFile(p, destFile);
|
|
1831
2101
|
break;
|
|
1832
2102
|
}
|
|
@@ -1849,7 +2119,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1849
2119
|
const { count, size } = await injectManifest(mergedOptions);
|
|
1850
2120
|
logger.info("pwa", `Injected manifest into '${swDest}', precaching ${count} files (${size} bytes)`);
|
|
1851
2121
|
}
|
|
1852
|
-
if (
|
|
2122
|
+
if (existsSync4(swDest) && config.pwa.version) {
|
|
1853
2123
|
let swContent = await fs5.readFile(swDest, "utf-8");
|
|
1854
2124
|
swContent = swContent.replaceAll("{{ version }}", config.pwa.version).replaceAll("{{version}}", config.pwa.version);
|
|
1855
2125
|
await fs5.writeFile(swDest, swContent, "utf-8");
|
|
@@ -1862,7 +2132,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1862
2132
|
|
|
1863
2133
|
// src/tasks/zip.ts
|
|
1864
2134
|
import fs6 from "fs";
|
|
1865
|
-
import
|
|
2135
|
+
import path21 from "path";
|
|
1866
2136
|
import archiver from "archiver";
|
|
1867
2137
|
import fg5 from "fast-glob";
|
|
1868
2138
|
var ZipTask = class extends BaseTask {
|
|
@@ -1873,9 +2143,9 @@ var ZipTask = class extends BaseTask {
|
|
|
1873
2143
|
}
|
|
1874
2144
|
async run(config) {
|
|
1875
2145
|
const input = this.options.input || config.dest.base;
|
|
1876
|
-
const outputDir = this.options.output ?
|
|
2146
|
+
const outputDir = this.options.output ? path21.isAbsolute(this.options.output) ? this.options.output : path21.join(config.workspace, this.options.output) : config.workspace;
|
|
1877
2147
|
const filename = this.options.filename || "archive.zip";
|
|
1878
|
-
const zipPath =
|
|
2148
|
+
const zipPath = path21.join(outputDir, filename);
|
|
1879
2149
|
await file.ensureDir(outputDir);
|
|
1880
2150
|
return new Promise((resolve, reject) => {
|
|
1881
2151
|
const outputStream = fs6.createWriteStream(zipPath);
|
|
@@ -1896,18 +2166,18 @@ var ZipTask = class extends BaseTask {
|
|
|
1896
2166
|
const base = item.split("*")[0].replace(/\/+$/, "") || ".";
|
|
1897
2167
|
const matched = fg5.sync(item, { cwd: config.workspace, onlyFiles: true, dot: true });
|
|
1898
2168
|
for (const relPath of matched) {
|
|
1899
|
-
const fullFilePath =
|
|
1900
|
-
const zipName =
|
|
2169
|
+
const fullFilePath = path21.join(config.workspace, relPath);
|
|
2170
|
+
const zipName = path21.relative(base, relPath);
|
|
1901
2171
|
archive.file(fullFilePath, { name: zipName });
|
|
1902
2172
|
}
|
|
1903
2173
|
} else {
|
|
1904
|
-
const fullPath =
|
|
2174
|
+
const fullPath = path21.isAbsolute(item) ? item : path21.join(config.workspace, item);
|
|
1905
2175
|
if (fs6.existsSync(fullPath)) {
|
|
1906
2176
|
const stat = fs6.statSync(fullPath);
|
|
1907
2177
|
if (stat.isDirectory()) {
|
|
1908
2178
|
archive.directory(fullPath, false);
|
|
1909
2179
|
} else {
|
|
1910
|
-
archive.file(fullPath, { name:
|
|
2180
|
+
archive.file(fullPath, { name: path21.basename(fullPath) });
|
|
1911
2181
|
}
|
|
1912
2182
|
}
|
|
1913
2183
|
}
|
|
@@ -1918,7 +2188,7 @@ var ZipTask = class extends BaseTask {
|
|
|
1918
2188
|
};
|
|
1919
2189
|
|
|
1920
2190
|
// src/tasks/ftp.ts
|
|
1921
|
-
import
|
|
2191
|
+
import path22 from "path";
|
|
1922
2192
|
import { Client } from "ssh2";
|
|
1923
2193
|
import fg6 from "fast-glob";
|
|
1924
2194
|
var FtpTask = class extends BaseTask {
|
|
@@ -1954,8 +2224,8 @@ var FtpTask = class extends BaseTask {
|
|
|
1954
2224
|
}
|
|
1955
2225
|
let pending = files.length;
|
|
1956
2226
|
for (const file2 of files) {
|
|
1957
|
-
const rel =
|
|
1958
|
-
const remoteFile =
|
|
2227
|
+
const rel = path22.relative(config.workspace, file2);
|
|
2228
|
+
const remoteFile = path22.posix.join(options.remotePath, rel);
|
|
1959
2229
|
sftp.fastPut(file2, remoteFile, (putErr) => {
|
|
1960
2230
|
if (putErr) {
|
|
1961
2231
|
logger.error("ftp", `Failed uploading ${file2}: ${putErr.message}`);
|
|
@@ -1983,7 +2253,7 @@ var FtpTask = class extends BaseTask {
|
|
|
1983
2253
|
// src/tasks/server.ts
|
|
1984
2254
|
import http from "http";
|
|
1985
2255
|
import fs8 from "fs";
|
|
1986
|
-
import
|
|
2256
|
+
import path24 from "path";
|
|
1987
2257
|
import connect from "connect";
|
|
1988
2258
|
import serveStatic from "serve-static";
|
|
1989
2259
|
import { WebSocketServer, WebSocket } from "ws";
|
|
@@ -1991,6 +2261,7 @@ import { createProxyMiddleware } from "http-proxy-middleware";
|
|
|
1991
2261
|
|
|
1992
2262
|
// src/watcher/index.ts
|
|
1993
2263
|
import fs7 from "fs";
|
|
2264
|
+
import path23 from "path";
|
|
1994
2265
|
import pc3 from "picocolors";
|
|
1995
2266
|
var FileWatcher = class {
|
|
1996
2267
|
config;
|
|
@@ -2000,7 +2271,8 @@ var FileWatcher = class {
|
|
|
2000
2271
|
styleTask;
|
|
2001
2272
|
scriptTask;
|
|
2002
2273
|
htmlTask;
|
|
2003
|
-
|
|
2274
|
+
watchers = [];
|
|
2275
|
+
isRebuilding = false;
|
|
2004
2276
|
constructor(config, broadcast) {
|
|
2005
2277
|
this.config = config;
|
|
2006
2278
|
this.broadcast = broadcast;
|
|
@@ -2008,29 +2280,56 @@ var FileWatcher = class {
|
|
|
2008
2280
|
this.scriptTask = new ScriptTask();
|
|
2009
2281
|
this.htmlTask = new HtmlTask();
|
|
2010
2282
|
}
|
|
2283
|
+
getWatchDirs() {
|
|
2284
|
+
const candidates = [
|
|
2285
|
+
this.config.src.base,
|
|
2286
|
+
...this.config.scripts.includeJsResource || [],
|
|
2287
|
+
...this.config.styles.atImportPaths || []
|
|
2288
|
+
];
|
|
2289
|
+
const resolved = candidates.filter(Boolean).map((dir) => path23.isAbsolute(dir) ? dir : path23.resolve(this.config.workspace, dir)).filter((dir) => fs7.existsSync(dir) && !dir.includes(`${path23.sep}node_modules`));
|
|
2290
|
+
const unique = Array.from(new Set(resolved)).sort((a, b) => a.length - b.length);
|
|
2291
|
+
return unique.filter(
|
|
2292
|
+
(dir, index) => !unique.slice(0, index).some((parent) => dir.startsWith(`${parent}${path23.sep}`))
|
|
2293
|
+
);
|
|
2294
|
+
}
|
|
2011
2295
|
start() {
|
|
2012
|
-
const
|
|
2013
|
-
if (!
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2296
|
+
const watchDirs = this.getWatchDirs();
|
|
2297
|
+
if (!watchDirs.length) return;
|
|
2298
|
+
for (const watchDir of watchDirs) {
|
|
2299
|
+
logger.info("watch", `Watching for file changes in ${pc3.cyan(watchDir)}`);
|
|
2300
|
+
try {
|
|
2301
|
+
const watcher = fs7.watch(watchDir, { recursive: true }, (_eventType, filename) => {
|
|
2302
|
+
if (!filename) return;
|
|
2303
|
+
const normalized = filename.replace(/\\/g, "/");
|
|
2304
|
+
if (normalized.includes("node_modules/") || normalized.startsWith(".git/")) {
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
this.pendingFiles.add(filename);
|
|
2308
|
+
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
2309
|
+
this.debounceTimer = setTimeout(() => {
|
|
2310
|
+
this.handleChanges();
|
|
2311
|
+
}, 50);
|
|
2312
|
+
});
|
|
2313
|
+
this.watchers.push(watcher);
|
|
2314
|
+
} catch (err) {
|
|
2315
|
+
logger.warn("watch", `Native recursive watch failed for ${watchDir}: ${err.message}`);
|
|
2316
|
+
}
|
|
2026
2317
|
}
|
|
2027
2318
|
}
|
|
2028
2319
|
async handleChanges() {
|
|
2320
|
+
if (this.isRebuilding) {
|
|
2321
|
+
this.debounceTimer = setTimeout(() => this.handleChanges(), 50);
|
|
2322
|
+
return;
|
|
2323
|
+
}
|
|
2029
2324
|
const changed = Array.from(this.pendingFiles);
|
|
2030
2325
|
this.pendingFiles.clear();
|
|
2326
|
+
if (!changed.length) return;
|
|
2031
2327
|
const hasStyle = changed.some((f) => /\.(scss|sass|less|css)$/i.test(f));
|
|
2032
|
-
const hasScript = changed.some(
|
|
2328
|
+
const hasScript = changed.some(
|
|
2329
|
+
(f) => /\.(js|mjs|cjs|ts|jsx|tsx|vue|md|json)$/i.test(f)
|
|
2330
|
+
);
|
|
2033
2331
|
const hasHtml = changed.some((f) => /\.html$/i.test(f));
|
|
2332
|
+
this.isRebuilding = true;
|
|
2034
2333
|
try {
|
|
2035
2334
|
if (hasStyle) {
|
|
2036
2335
|
const start = performance.now();
|
|
@@ -2058,13 +2357,19 @@ var FileWatcher = class {
|
|
|
2058
2357
|
}
|
|
2059
2358
|
} catch (err) {
|
|
2060
2359
|
logger.error("watch", `Incremental rebuild failed: ${err?.message || err}`);
|
|
2360
|
+
} finally {
|
|
2361
|
+
this.isRebuilding = false;
|
|
2061
2362
|
}
|
|
2062
2363
|
}
|
|
2063
2364
|
stop() {
|
|
2064
|
-
if (this.
|
|
2065
|
-
this.
|
|
2066
|
-
this.
|
|
2365
|
+
if (this.debounceTimer) {
|
|
2366
|
+
clearTimeout(this.debounceTimer);
|
|
2367
|
+
this.debounceTimer = null;
|
|
2368
|
+
}
|
|
2369
|
+
for (const watcher of this.watchers) {
|
|
2370
|
+
watcher.close();
|
|
2067
2371
|
}
|
|
2372
|
+
this.watchers = [];
|
|
2068
2373
|
}
|
|
2069
2374
|
};
|
|
2070
2375
|
|
|
@@ -2102,9 +2407,9 @@ var ServerTask = class extends BaseTask {
|
|
|
2102
2407
|
app.use((req, res, next) => {
|
|
2103
2408
|
if (req.url === "/manifest.json" || req.url?.endsWith("/manifest.json")) {
|
|
2104
2409
|
const candidates = [
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2410
|
+
path24.join(config.dest.base, "manifest.json"),
|
|
2411
|
+
path24.join(config.src.base, "manifest.json"),
|
|
2412
|
+
path24.join(config.workspace, "manifest.json")
|
|
2108
2413
|
];
|
|
2109
2414
|
const file2 = candidates.find((f) => fs8.existsSync(f));
|
|
2110
2415
|
if (file2) {
|
|
@@ -2129,37 +2434,37 @@ var ServerTask = class extends BaseTask {
|
|
|
2129
2434
|
if (config.paths.tmp.js && config.paths.tmp.js !== config.paths.source.js) {
|
|
2130
2435
|
app.use("/" + config.paths.tmp.js, serveStatic(config.dest.js));
|
|
2131
2436
|
}
|
|
2132
|
-
app.use("/chunk", serveStatic(
|
|
2133
|
-
app.use("/chunk", serveStatic(
|
|
2437
|
+
app.use("/chunk", serveStatic(path24.join(config.dest.js, "chunk")));
|
|
2438
|
+
app.use("/chunk", serveStatic(path24.join(config.dest.base, "chunk")));
|
|
2134
2439
|
if (config.paths.source.img) {
|
|
2135
2440
|
app.use(
|
|
2136
2441
|
"/" + config.paths.source.img,
|
|
2137
|
-
serveStatic(
|
|
2442
|
+
serveStatic(path24.join(config.src.base, config.paths.source.img))
|
|
2138
2443
|
);
|
|
2139
2444
|
}
|
|
2140
2445
|
if (config.paths.tmp.img) {
|
|
2141
2446
|
app.use("/" + config.paths.tmp.img, serveStatic(config.dest.img));
|
|
2142
2447
|
}
|
|
2143
|
-
app.use("/img", serveStatic(
|
|
2144
|
-
app.use("/img", serveStatic(
|
|
2448
|
+
app.use("/img", serveStatic(path24.join(config.dest.base, "img")));
|
|
2449
|
+
app.use("/img", serveStatic(path24.join(config.dest.js, "img")));
|
|
2145
2450
|
if (config.paths.source.font) {
|
|
2146
2451
|
app.use(
|
|
2147
2452
|
"/" + config.paths.source.font,
|
|
2148
|
-
serveStatic(
|
|
2453
|
+
serveStatic(path24.join(config.src.base, config.paths.source.font))
|
|
2149
2454
|
);
|
|
2150
2455
|
}
|
|
2151
2456
|
if (config.paths.tmp.font) {
|
|
2152
2457
|
app.use("/" + config.paths.tmp.font, serveStatic(config.dest.font));
|
|
2153
2458
|
}
|
|
2154
|
-
app.use("/font", serveStatic(
|
|
2155
|
-
app.use("/font", serveStatic(
|
|
2156
|
-
app.use("/fonts", serveStatic(
|
|
2157
|
-
app.use("/fonts", serveStatic(
|
|
2459
|
+
app.use("/font", serveStatic(path24.join(config.dest.base, "font")));
|
|
2460
|
+
app.use("/font", serveStatic(path24.join(config.dest.js, "font")));
|
|
2461
|
+
app.use("/fonts", serveStatic(path24.join(config.src.base, "fonts")));
|
|
2462
|
+
app.use("/fonts", serveStatic(path24.join(config.dest.base, "fonts")));
|
|
2158
2463
|
if (config.server.serveStatic) {
|
|
2159
2464
|
const staticEntries = Array.isArray(config.server.serveStatic) ? config.server.serveStatic : [config.server.serveStatic];
|
|
2160
2465
|
for (const entry of staticEntries) {
|
|
2161
2466
|
if (typeof entry === "string") {
|
|
2162
|
-
const absoluteDir =
|
|
2467
|
+
const absoluteDir = path24.isAbsolute(entry) ? entry : path24.join(config.workspace, entry);
|
|
2163
2468
|
if (fs8.existsSync(absoluteDir)) {
|
|
2164
2469
|
app.use(serveStatic(absoluteDir));
|
|
2165
2470
|
}
|
|
@@ -2167,7 +2472,7 @@ var ServerTask = class extends BaseTask {
|
|
|
2167
2472
|
const route = entry.route ? entry.route.startsWith("/") ? entry.route : `/${entry.route}` : "";
|
|
2168
2473
|
const dirs = Array.isArray(entry.dir) ? entry.dir : [entry.dir];
|
|
2169
2474
|
for (const dir of dirs) {
|
|
2170
|
-
const absoluteDir =
|
|
2475
|
+
const absoluteDir = path24.isAbsolute(dir) ? dir : path24.join(config.workspace, dir);
|
|
2171
2476
|
if (fs8.existsSync(absoluteDir)) {
|
|
2172
2477
|
if (route) {
|
|
2173
2478
|
app.use(route, serveStatic(absoluteDir));
|
|
@@ -2187,8 +2492,8 @@ var ServerTask = class extends BaseTask {
|
|
|
2187
2492
|
const isGetOrHead = req.method === "GET" || req.method === "HEAD";
|
|
2188
2493
|
const isHtmlNav = !req.url?.includes(".") || req.headers.accept?.includes("text/html");
|
|
2189
2494
|
if (isGetOrHead && isHtmlNav) {
|
|
2190
|
-
const indexPath =
|
|
2191
|
-
const srcIndexPath =
|
|
2495
|
+
const indexPath = path24.join(config.dest.html, "index.html");
|
|
2496
|
+
const srcIndexPath = path24.join(config.src.base, "index.html");
|
|
2192
2497
|
const fileToServe = fs8.existsSync(indexPath) ? indexPath : srcIndexPath;
|
|
2193
2498
|
if (fs8.existsSync(fileToServe)) {
|
|
2194
2499
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
@@ -2238,8 +2543,8 @@ var ServerTask = class extends BaseTask {
|
|
|
2238
2543
|
};
|
|
2239
2544
|
|
|
2240
2545
|
// src/tasks/static.ts
|
|
2241
|
-
import
|
|
2242
|
-
import { existsSync as
|
|
2546
|
+
import path25 from "path";
|
|
2547
|
+
import { existsSync as existsSync5 } from "fs";
|
|
2243
2548
|
var StaticTask = class extends BaseTask {
|
|
2244
2549
|
constructor() {
|
|
2245
2550
|
super({ name: "static", description: "Copy static assets, images, fonts, and manifest" });
|
|
@@ -2248,47 +2553,67 @@ var StaticTask = class extends BaseTask {
|
|
|
2248
2553
|
const srcBase = config.src.base;
|
|
2249
2554
|
const destBase = config.dest.base;
|
|
2250
2555
|
const staticPatterns = [
|
|
2251
|
-
|
|
2252
|
-
`!${
|
|
2556
|
+
path25.join(srcBase, "*.{ico,png,svg,json,txt,xml,webmanifest}"),
|
|
2557
|
+
`!${path25.join(srcBase, "*.html")}`
|
|
2558
|
+
];
|
|
2559
|
+
const extraIncludes = [
|
|
2560
|
+
...config.extras?.includes || [],
|
|
2561
|
+
...config.assets?.includes || []
|
|
2253
2562
|
];
|
|
2563
|
+
const extraExcludes = [
|
|
2564
|
+
...config.extras?.excludes || [],
|
|
2565
|
+
...config.assets?.excludes || []
|
|
2566
|
+
];
|
|
2567
|
+
for (const inc of extraIncludes) {
|
|
2568
|
+
const pattern = path25.isAbsolute(inc) ? inc : path25.join(srcBase, inc);
|
|
2569
|
+
staticPatterns.push(pattern);
|
|
2570
|
+
}
|
|
2571
|
+
for (const exc of extraExcludes) {
|
|
2572
|
+
const pattern = path25.isAbsolute(exc) ? exc : path25.join(srcBase, exc);
|
|
2573
|
+
staticPatterns.push(`!${pattern}`);
|
|
2574
|
+
}
|
|
2254
2575
|
const pipeline = Pipeline.from(staticPatterns, {
|
|
2255
2576
|
cwd: config.workspace,
|
|
2256
2577
|
base: srcBase
|
|
2257
2578
|
});
|
|
2258
2579
|
const publicUrlReplacement = config.assets.virtualDir ? `/${config.assets.virtualDir}` : "";
|
|
2259
2580
|
pipeline.pipe(async (file2) => {
|
|
2260
|
-
|
|
2581
|
+
const isManifest = isManifestFile(file2, config);
|
|
2582
|
+
if (isManifest || file2.extname === ".json") {
|
|
2261
2583
|
let content = file2.toString();
|
|
2262
2584
|
content = content.replaceAll(PUBLIC_URL, publicUrlReplacement);
|
|
2585
|
+
if (isManifest) {
|
|
2586
|
+
content = rewriteHtmlAssetPaths(content, config);
|
|
2587
|
+
}
|
|
2263
2588
|
file2.contents = Buffer.from(content);
|
|
2264
2589
|
}
|
|
2265
2590
|
return file2;
|
|
2266
2591
|
});
|
|
2267
2592
|
await pipeline.dest(destBase);
|
|
2268
|
-
if (config.src.img &&
|
|
2269
|
-
const imgPipeline = Pipeline.from(
|
|
2593
|
+
if (config.src.img && existsSync5(config.src.img)) {
|
|
2594
|
+
const imgPipeline = Pipeline.from(path25.join(config.src.img, "**/*"), {
|
|
2270
2595
|
cwd: config.workspace,
|
|
2271
2596
|
base: config.src.img
|
|
2272
2597
|
});
|
|
2273
2598
|
await imgPipeline.dest(config.dest.img);
|
|
2274
2599
|
}
|
|
2275
|
-
if (config.src.font &&
|
|
2276
|
-
const fontPipeline = Pipeline.from(
|
|
2600
|
+
if (config.src.font && existsSync5(config.src.font)) {
|
|
2601
|
+
const fontPipeline = Pipeline.from(path25.join(config.src.font, "**/*"), {
|
|
2277
2602
|
cwd: config.workspace,
|
|
2278
2603
|
base: config.src.font
|
|
2279
2604
|
});
|
|
2280
2605
|
await fontPipeline.dest(config.dest.font);
|
|
2281
2606
|
}
|
|
2282
|
-
if (config.src.media &&
|
|
2283
|
-
const mediaPipeline = Pipeline.from(
|
|
2607
|
+
if (config.src.media && existsSync5(config.src.media)) {
|
|
2608
|
+
const mediaPipeline = Pipeline.from(path25.join(config.src.media, "**/*"), {
|
|
2284
2609
|
cwd: config.workspace,
|
|
2285
2610
|
base: config.src.media
|
|
2286
2611
|
});
|
|
2287
2612
|
await mediaPipeline.dest(config.dest.media);
|
|
2288
2613
|
}
|
|
2289
|
-
const publicDir =
|
|
2290
|
-
if (
|
|
2291
|
-
const pubPipeline = Pipeline.from(
|
|
2614
|
+
const publicDir = path25.join(config.workspace, "public");
|
|
2615
|
+
if (existsSync5(publicDir)) {
|
|
2616
|
+
const pubPipeline = Pipeline.from(path25.join(publicDir, "**/*"), {
|
|
2292
2617
|
cwd: config.workspace,
|
|
2293
2618
|
base: publicDir
|
|
2294
2619
|
});
|
|
@@ -2487,7 +2812,7 @@ var Balm = class {
|
|
|
2487
2812
|
}
|
|
2488
2813
|
try {
|
|
2489
2814
|
if (this.beforeTask) {
|
|
2490
|
-
await this.beforeTask();
|
|
2815
|
+
await this.beforeTask(this._config);
|
|
2491
2816
|
}
|
|
2492
2817
|
if (this._config.useDefaults) {
|
|
2493
2818
|
await this.dag.runSeries(
|
|
@@ -2512,7 +2837,7 @@ var Balm = class {
|
|
|
2512
2837
|
await this.dag.executeTask("serve", this._config);
|
|
2513
2838
|
}
|
|
2514
2839
|
if (this.afterTask) {
|
|
2515
|
-
await this.afterTask();
|
|
2840
|
+
await this.afterTask(this._config);
|
|
2516
2841
|
}
|
|
2517
2842
|
endTimer();
|
|
2518
2843
|
} catch (err) {
|
|
@@ -2591,6 +2916,7 @@ export {
|
|
|
2591
2916
|
isArray,
|
|
2592
2917
|
isBoolean,
|
|
2593
2918
|
isFunction,
|
|
2919
|
+
isManifestFile,
|
|
2594
2920
|
isObject,
|
|
2595
2921
|
isString,
|
|
2596
2922
|
localResolve,
|
|
@@ -2598,11 +2924,15 @@ export {
|
|
|
2598
2924
|
logger,
|
|
2599
2925
|
resolveConfig,
|
|
2600
2926
|
resolveDefaultEntry,
|
|
2927
|
+
rewriteCssAssetUrls,
|
|
2928
|
+
rewriteHtmlAssetPaths,
|
|
2601
2929
|
runEsbuild,
|
|
2602
2930
|
runRollup,
|
|
2603
2931
|
runWebpack,
|
|
2604
2932
|
setWorkspaces,
|
|
2933
|
+
shouldUseTargetPaths,
|
|
2605
2934
|
toNamespace,
|
|
2935
|
+
transformCssUrl,
|
|
2606
2936
|
transformHtmlmin,
|
|
2607
2937
|
transformLess,
|
|
2608
2938
|
transformPostcss,
|