@arkxio/ark-dev-utils 0.1.8 → 0.1.10
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.js +136 -128
- package/dist/index.min.js +136 -128
- package/lib/index.js +136 -128
- package/package.json +51 -51
- package/src/ArkWebpackPlugin.js +143 -135
- package/LICENSE +0 -170
package/dist/index.js
CHANGED
|
@@ -1179,134 +1179,142 @@
|
|
|
1179
1179
|
|
|
1180
1180
|
};
|
|
1181
1181
|
|
|
1182
|
-
class ArkWebpackPlugin {
|
|
1183
|
-
|
|
1184
|
-
constructor(options) {
|
|
1185
|
-
this.metaOptions = options;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
apply(compiler) {
|
|
1189
|
-
// 获取项目根目录路径
|
|
1190
|
-
compiler.context;
|
|
1191
|
-
const useExtractOptions = this.metaOptions;
|
|
1192
|
-
|
|
1193
|
-
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1194
|
-
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1195
|
-
resetScriptIdx();
|
|
1196
|
-
});
|
|
1197
|
-
|
|
1198
|
-
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1199
|
-
compilation.hooks.processAssets.tap(
|
|
1200
|
-
{
|
|
1201
|
-
name: 'ArkDynamicCdnChunkLoaderPlugin',
|
|
1202
|
-
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
|
1203
|
-
},
|
|
1204
|
-
(assets) => {
|
|
1205
|
-
// 新增分块文件过滤逻辑
|
|
1206
|
-
const chunkFiles = new Set();
|
|
1207
|
-
compilation.chunks.forEach(chunk => {
|
|
1208
|
-
chunk.files.forEach(file => {
|
|
1209
|
-
if (file.endsWith('.js')) chunkFiles.add(file);
|
|
1210
|
-
});
|
|
1211
|
-
});
|
|
1212
|
-
// 调试日志
|
|
1213
|
-
verbose('[分块文件列表]', Array.from(chunkFiles));
|
|
1214
|
-
|
|
1215
|
-
Object.entries(assets).forEach(([filename, source]) => {
|
|
1216
|
-
// 仅处理分块JS文件
|
|
1217
|
-
if (!chunkFiles.has(filename)) return;
|
|
1218
|
-
|
|
1219
|
-
// 检查资源内容有效性
|
|
1220
|
-
if (
|
|
1221
|
-
!source ||
|
|
1222
|
-
!source.source ||
|
|
1223
|
-
typeof source.source() !== 'string' ||
|
|
1224
|
-
source.source().trim() === ''
|
|
1225
|
-
) {
|
|
1226
|
-
console.warn(`资源 ${filename} 内容为空或无效,跳过处理`);
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
let content = source.source().toString();
|
|
1231
|
-
|
|
1232
|
-
// 替换逻辑
|
|
1233
|
-
// /(__webpack_require__\.l)\(url,/g)
|
|
1234
|
-
// const webpackRequireLPattern = /(__webpack_require__\.l)\(url,/g;
|
|
1235
|
-
// if (webpackRequireLPattern.test(content)) {
|
|
1236
|
-
// verbose('检测到 __webpack_require__.l 模式');
|
|
1237
|
-
// content = content.replace(
|
|
1238
|
-
// webpackRequireLPattern,
|
|
1239
|
-
// `(function(url, done, key, chunkId) {
|
|
1240
|
-
// if (typeof window.ArkConfig !== 'undefined' && window.ArkConfig.cdnHost) {
|
|
1241
|
-
// if (!url.startsWith(window.ArkConfig.cdnHost) && url.startsWith('https://unpkg.com')) {
|
|
1242
|
-
// url = window.ArkConfig.cdnHost + url.slice('https://unpkg.com'.length);
|
|
1243
|
-
// }
|
|
1244
|
-
// }
|
|
1245
|
-
// return $1(url, done, key, chunkId);
|
|
1246
|
-
// })(url,`
|
|
1247
|
-
// );
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1182
|
+
class ArkWebpackPlugin {
|
|
1183
|
+
|
|
1184
|
+
constructor(options) {
|
|
1185
|
+
this.metaOptions = options;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
apply(compiler) {
|
|
1189
|
+
// 获取项目根目录路径
|
|
1190
|
+
compiler.context;
|
|
1191
|
+
const useExtractOptions = this.metaOptions;
|
|
1192
|
+
|
|
1193
|
+
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1194
|
+
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1195
|
+
resetScriptIdx();
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1199
|
+
compilation.hooks.processAssets.tap(
|
|
1200
|
+
{
|
|
1201
|
+
name: 'ArkDynamicCdnChunkLoaderPlugin',
|
|
1202
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
|
1203
|
+
},
|
|
1204
|
+
(assets) => {
|
|
1205
|
+
// 新增分块文件过滤逻辑
|
|
1206
|
+
const chunkFiles = new Set();
|
|
1207
|
+
compilation.chunks.forEach(chunk => {
|
|
1208
|
+
chunk.files.forEach(file => {
|
|
1209
|
+
if (file.endsWith('.js')) chunkFiles.add(file);
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
// 调试日志
|
|
1213
|
+
verbose('[分块文件列表]', Array.from(chunkFiles));
|
|
1214
|
+
|
|
1215
|
+
Object.entries(assets).forEach(([filename, source]) => {
|
|
1216
|
+
// 仅处理分块JS文件
|
|
1217
|
+
if (!chunkFiles.has(filename)) return;
|
|
1218
|
+
|
|
1219
|
+
// 检查资源内容有效性
|
|
1220
|
+
if (
|
|
1221
|
+
!source ||
|
|
1222
|
+
!source.source ||
|
|
1223
|
+
typeof source.source() !== 'string' ||
|
|
1224
|
+
source.source().trim() === ''
|
|
1225
|
+
) {
|
|
1226
|
+
console.warn(`资源 ${filename} 内容为空或无效,跳过处理`);
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
let content = source.source().toString();
|
|
1231
|
+
|
|
1232
|
+
// 替换逻辑
|
|
1233
|
+
// /(__webpack_require__\.l)\(url,/g)
|
|
1234
|
+
// const webpackRequireLPattern = /(__webpack_require__\.l)\(url,/g;
|
|
1235
|
+
// if (webpackRequireLPattern.test(content)) {
|
|
1236
|
+
// verbose('检测到 __webpack_require__.l 模式');
|
|
1237
|
+
// content = content.replace(
|
|
1238
|
+
// webpackRequireLPattern,
|
|
1239
|
+
// `(function(url, done, key, chunkId) {
|
|
1240
|
+
// if (typeof window.ArkConfig !== 'undefined' && window.ArkConfig.cdnHost) {
|
|
1241
|
+
// if (!url.startsWith(window.ArkConfig.cdnHost) && url.startsWith('https://unpkg.com')) {
|
|
1242
|
+
// url = window.ArkConfig.cdnHost + url.slice('https://unpkg.com'.length);
|
|
1243
|
+
// }
|
|
1244
|
+
// }
|
|
1245
|
+
// return $1(url, done, key, chunkId);
|
|
1246
|
+
// })(url,`
|
|
1247
|
+
// );
|
|
1248
|
+
|
|
1249
|
+
let findUnpkgModel = false;
|
|
1250
|
+
const webpackRequireLPatternEval = /"https:\/\/unpkg\.com"/g;
|
|
1251
|
+
if (webpackRequireLPatternEval.test(content)) {
|
|
1252
|
+
content = content.replace(webpackRequireLPatternEval, 'window.ArkConfig.cdnHost');
|
|
1253
|
+
findUnpkgModel = true;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const webpackRequireLPattern = /"(https:\/\/unpkg\.com)/g;
|
|
1257
|
+
if (webpackRequireLPattern.test(content)) {
|
|
1258
|
+
findUnpkgModel = true;
|
|
1259
|
+
verbose('检测到 unpkg.com 模式');
|
|
1260
|
+
content = content.replace(
|
|
1261
|
+
webpackRequireLPattern,
|
|
1262
|
+
`window.ArkConfig.cdnHost + "`
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
if (findUnpkgModel) {
|
|
1267
|
+
// 更新资源
|
|
1268
|
+
compilation.updateAsset(filename, new compiler.webpack.sources.RawSource(content));
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
);
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1277
|
+
// 注入环境判断脚本
|
|
1278
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
1279
|
+
|
|
1280
|
+
// 收集所有生成的JS文件
|
|
1281
|
+
const outputPath = compilation.options.output.publicPath || '';
|
|
1282
|
+
const jsFiles = [];
|
|
1283
|
+
|
|
1284
|
+
// Webpack 5 正确的API:使用 getAssets()
|
|
1285
|
+
const assets = compilation.getAssets ? compilation.getAssets() : compilation.assets;
|
|
1286
|
+
|
|
1287
|
+
// 遍历所有资产,收集JS文件
|
|
1288
|
+
assets.forEach((asset) => {
|
|
1289
|
+
const assetName = asset.name || asset;
|
|
1290
|
+
if (assetName.endsWith('.js')) {
|
|
1291
|
+
console.log('Found JS file:', assetName);
|
|
1292
|
+
// 排除 ark-meta.json 和 ark_userChunk 文件
|
|
1293
|
+
if (assetName.indexOf('js/app.') !== -1 ||
|
|
1294
|
+
assetName.indexOf('js/runtime.') !== -1 ||
|
|
1295
|
+
assetName.indexOf('js/vendors.') !== -1 ||
|
|
1296
|
+
assetName.indexOf('js/main.') !== -1) {
|
|
1297
|
+
jsFiles.push(outputPath + assetName);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
console.log('Final JS files for chunkJsSrcList:', jsFiles);
|
|
1303
|
+
|
|
1304
|
+
// 创建 customAssets 数组用于收集自定义资产(如从 HTML 内联 script 提取的代码)
|
|
1305
|
+
const customAssets = [];
|
|
1306
|
+
|
|
1307
|
+
await extractArkMetaJson({
|
|
1308
|
+
...useExtractOptions,
|
|
1309
|
+
chunkJsFiles: jsFiles,
|
|
1310
|
+
isDev: isDev,
|
|
1311
|
+
compilation: compilation,
|
|
1312
|
+
customAssets: customAssets
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
return Promise.resolve();
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1310
1318
|
}
|
|
1311
1319
|
|
|
1312
1320
|
var index = {
|
package/dist/index.min.js
CHANGED
|
@@ -1179,134 +1179,142 @@
|
|
|
1179
1179
|
|
|
1180
1180
|
};
|
|
1181
1181
|
|
|
1182
|
-
class ArkWebpackPlugin {
|
|
1183
|
-
|
|
1184
|
-
constructor(options) {
|
|
1185
|
-
this.metaOptions = options;
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
apply(compiler) {
|
|
1189
|
-
// 获取项目根目录路径
|
|
1190
|
-
compiler.context;
|
|
1191
|
-
const useExtractOptions = this.metaOptions;
|
|
1192
|
-
|
|
1193
|
-
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1194
|
-
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1195
|
-
resetScriptIdx();
|
|
1196
|
-
});
|
|
1197
|
-
|
|
1198
|
-
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1199
|
-
compilation.hooks.processAssets.tap(
|
|
1200
|
-
{
|
|
1201
|
-
name: 'ArkDynamicCdnChunkLoaderPlugin',
|
|
1202
|
-
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
|
1203
|
-
},
|
|
1204
|
-
(assets) => {
|
|
1205
|
-
// 新增分块文件过滤逻辑
|
|
1206
|
-
const chunkFiles = new Set();
|
|
1207
|
-
compilation.chunks.forEach(chunk => {
|
|
1208
|
-
chunk.files.forEach(file => {
|
|
1209
|
-
if (file.endsWith('.js')) chunkFiles.add(file);
|
|
1210
|
-
});
|
|
1211
|
-
});
|
|
1212
|
-
// 调试日志
|
|
1213
|
-
verbose('[分块文件列表]', Array.from(chunkFiles));
|
|
1214
|
-
|
|
1215
|
-
Object.entries(assets).forEach(([filename, source]) => {
|
|
1216
|
-
// 仅处理分块JS文件
|
|
1217
|
-
if (!chunkFiles.has(filename)) return;
|
|
1218
|
-
|
|
1219
|
-
// 检查资源内容有效性
|
|
1220
|
-
if (
|
|
1221
|
-
!source ||
|
|
1222
|
-
!source.source ||
|
|
1223
|
-
typeof source.source() !== 'string' ||
|
|
1224
|
-
source.source().trim() === ''
|
|
1225
|
-
) {
|
|
1226
|
-
console.warn(`资源 ${filename} 内容为空或无效,跳过处理`);
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
let content = source.source().toString();
|
|
1231
|
-
|
|
1232
|
-
// 替换逻辑
|
|
1233
|
-
// /(__webpack_require__\.l)\(url,/g)
|
|
1234
|
-
// const webpackRequireLPattern = /(__webpack_require__\.l)\(url,/g;
|
|
1235
|
-
// if (webpackRequireLPattern.test(content)) {
|
|
1236
|
-
// verbose('检测到 __webpack_require__.l 模式');
|
|
1237
|
-
// content = content.replace(
|
|
1238
|
-
// webpackRequireLPattern,
|
|
1239
|
-
// `(function(url, done, key, chunkId) {
|
|
1240
|
-
// if (typeof window.ArkConfig !== 'undefined' && window.ArkConfig.cdnHost) {
|
|
1241
|
-
// if (!url.startsWith(window.ArkConfig.cdnHost) && url.startsWith('https://unpkg.com')) {
|
|
1242
|
-
// url = window.ArkConfig.cdnHost + url.slice('https://unpkg.com'.length);
|
|
1243
|
-
// }
|
|
1244
|
-
// }
|
|
1245
|
-
// return $1(url, done, key, chunkId);
|
|
1246
|
-
// })(url,`
|
|
1247
|
-
// );
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1182
|
+
class ArkWebpackPlugin {
|
|
1183
|
+
|
|
1184
|
+
constructor(options) {
|
|
1185
|
+
this.metaOptions = options;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
apply(compiler) {
|
|
1189
|
+
// 获取项目根目录路径
|
|
1190
|
+
compiler.context;
|
|
1191
|
+
const useExtractOptions = this.metaOptions;
|
|
1192
|
+
|
|
1193
|
+
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1194
|
+
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1195
|
+
resetScriptIdx();
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1199
|
+
compilation.hooks.processAssets.tap(
|
|
1200
|
+
{
|
|
1201
|
+
name: 'ArkDynamicCdnChunkLoaderPlugin',
|
|
1202
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
|
|
1203
|
+
},
|
|
1204
|
+
(assets) => {
|
|
1205
|
+
// 新增分块文件过滤逻辑
|
|
1206
|
+
const chunkFiles = new Set();
|
|
1207
|
+
compilation.chunks.forEach(chunk => {
|
|
1208
|
+
chunk.files.forEach(file => {
|
|
1209
|
+
if (file.endsWith('.js')) chunkFiles.add(file);
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
// 调试日志
|
|
1213
|
+
verbose('[分块文件列表]', Array.from(chunkFiles));
|
|
1214
|
+
|
|
1215
|
+
Object.entries(assets).forEach(([filename, source]) => {
|
|
1216
|
+
// 仅处理分块JS文件
|
|
1217
|
+
if (!chunkFiles.has(filename)) return;
|
|
1218
|
+
|
|
1219
|
+
// 检查资源内容有效性
|
|
1220
|
+
if (
|
|
1221
|
+
!source ||
|
|
1222
|
+
!source.source ||
|
|
1223
|
+
typeof source.source() !== 'string' ||
|
|
1224
|
+
source.source().trim() === ''
|
|
1225
|
+
) {
|
|
1226
|
+
console.warn(`资源 ${filename} 内容为空或无效,跳过处理`);
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
let content = source.source().toString();
|
|
1231
|
+
|
|
1232
|
+
// 替换逻辑
|
|
1233
|
+
// /(__webpack_require__\.l)\(url,/g)
|
|
1234
|
+
// const webpackRequireLPattern = /(__webpack_require__\.l)\(url,/g;
|
|
1235
|
+
// if (webpackRequireLPattern.test(content)) {
|
|
1236
|
+
// verbose('检测到 __webpack_require__.l 模式');
|
|
1237
|
+
// content = content.replace(
|
|
1238
|
+
// webpackRequireLPattern,
|
|
1239
|
+
// `(function(url, done, key, chunkId) {
|
|
1240
|
+
// if (typeof window.ArkConfig !== 'undefined' && window.ArkConfig.cdnHost) {
|
|
1241
|
+
// if (!url.startsWith(window.ArkConfig.cdnHost) && url.startsWith('https://unpkg.com')) {
|
|
1242
|
+
// url = window.ArkConfig.cdnHost + url.slice('https://unpkg.com'.length);
|
|
1243
|
+
// }
|
|
1244
|
+
// }
|
|
1245
|
+
// return $1(url, done, key, chunkId);
|
|
1246
|
+
// })(url,`
|
|
1247
|
+
// );
|
|
1248
|
+
|
|
1249
|
+
let findUnpkgModel = false;
|
|
1250
|
+
const webpackRequireLPatternEval = /"https:\/\/unpkg\.com"/g;
|
|
1251
|
+
if (webpackRequireLPatternEval.test(content)) {
|
|
1252
|
+
content = content.replace(webpackRequireLPatternEval, 'window.ArkConfig.cdnHost');
|
|
1253
|
+
findUnpkgModel = true;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const webpackRequireLPattern = /"(https:\/\/unpkg\.com)/g;
|
|
1257
|
+
if (webpackRequireLPattern.test(content)) {
|
|
1258
|
+
findUnpkgModel = true;
|
|
1259
|
+
verbose('检测到 unpkg.com 模式');
|
|
1260
|
+
content = content.replace(
|
|
1261
|
+
webpackRequireLPattern,
|
|
1262
|
+
`window.ArkConfig.cdnHost + "`
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
if (findUnpkgModel) {
|
|
1267
|
+
// 更新资源
|
|
1268
|
+
compilation.updateAsset(filename, new compiler.webpack.sources.RawSource(content));
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
);
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1277
|
+
// 注入环境判断脚本
|
|
1278
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
1279
|
+
|
|
1280
|
+
// 收集所有生成的JS文件
|
|
1281
|
+
const outputPath = compilation.options.output.publicPath || '';
|
|
1282
|
+
const jsFiles = [];
|
|
1283
|
+
|
|
1284
|
+
// Webpack 5 正确的API:使用 getAssets()
|
|
1285
|
+
const assets = compilation.getAssets ? compilation.getAssets() : compilation.assets;
|
|
1286
|
+
|
|
1287
|
+
// 遍历所有资产,收集JS文件
|
|
1288
|
+
assets.forEach((asset) => {
|
|
1289
|
+
const assetName = asset.name || asset;
|
|
1290
|
+
if (assetName.endsWith('.js')) {
|
|
1291
|
+
console.log('Found JS file:', assetName);
|
|
1292
|
+
// 排除 ark-meta.json 和 ark_userChunk 文件
|
|
1293
|
+
if (assetName.indexOf('js/app.') !== -1 ||
|
|
1294
|
+
assetName.indexOf('js/runtime.') !== -1 ||
|
|
1295
|
+
assetName.indexOf('js/vendors.') !== -1 ||
|
|
1296
|
+
assetName.indexOf('js/main.') !== -1) {
|
|
1297
|
+
jsFiles.push(outputPath + assetName);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
console.log('Final JS files for chunkJsSrcList:', jsFiles);
|
|
1303
|
+
|
|
1304
|
+
// 创建 customAssets 数组用于收集自定义资产(如从 HTML 内联 script 提取的代码)
|
|
1305
|
+
const customAssets = [];
|
|
1306
|
+
|
|
1307
|
+
await extractArkMetaJson({
|
|
1308
|
+
...useExtractOptions,
|
|
1309
|
+
chunkJsFiles: jsFiles,
|
|
1310
|
+
isDev: isDev,
|
|
1311
|
+
compilation: compilation,
|
|
1312
|
+
customAssets: customAssets
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
return Promise.resolve();
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1310
1318
|
}
|
|
1311
1319
|
|
|
1312
1320
|
var index = {
|