@arkxio/ark-dev-utils 0.1.2 → 0.1.3
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/ark-dev-utils.js +25 -3
- package/dist/ark-dev-utils.min.js +25 -3
- package/lib/index.js +25 -3
- package/package.json +1 -1
- package/src/ArkWebpackPlugin.js +6 -1
- package/src/meta-extractor/fillAssetList.js +19 -2
- package/typings.d.ts +4 -0
package/dist/ark-dev-utils.js
CHANGED
|
@@ -582,7 +582,7 @@
|
|
|
582
582
|
* @param {IInnerFillAssetListOptions} options
|
|
583
583
|
*/
|
|
584
584
|
async function writeInnerText(childDom, fileType, options) {
|
|
585
|
-
const { homePage, buildDirFullPath } = options;
|
|
585
|
+
const { homePage, buildDirFullPath, compilation, customAssets = [] } = options;
|
|
586
586
|
const innerText = getInnerText(childDom);
|
|
587
587
|
if (!innerText) return '';
|
|
588
588
|
|
|
@@ -592,7 +592,24 @@
|
|
|
592
592
|
const fileAbsolutePath = `${buildDirFullPath}/${scriptName}`;
|
|
593
593
|
const fileWebPath = `${slash.noEnd(homePage)}/${scriptName}`;
|
|
594
594
|
|
|
595
|
-
|
|
595
|
+
// 在开发模式下,使用 compilation.emitAsset 确保文件能被 dev server 访问
|
|
596
|
+
if (compilation && compilation.emitAsset) {
|
|
597
|
+
const { sources } = compilation.compiler.webpack;
|
|
598
|
+
compilation.emitAsset(
|
|
599
|
+
scriptName,
|
|
600
|
+
new sources.RawSource(innerText)
|
|
601
|
+
);
|
|
602
|
+
verbose(`emit asset ${scriptName} via webpack compilation`);
|
|
603
|
+
} else {
|
|
604
|
+
// 生产模式或没有 compilation 对象时,直接写入文件系统
|
|
605
|
+
await writeFile(fileAbsolutePath, innerText);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// 将自定义资产信息保存到 customAssets 数组,供后续使用
|
|
609
|
+
if (customAssets) {
|
|
610
|
+
customAssets.push({ scriptName, fileWebPath, content: innerText });
|
|
611
|
+
}
|
|
612
|
+
|
|
596
613
|
verbose(`write done, the web file will be ${fileWebPath} later`);
|
|
597
614
|
return fileWebPath;
|
|
598
615
|
}
|
|
@@ -1236,11 +1253,16 @@
|
|
|
1236
1253
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1237
1254
|
// 注入环境判断脚本
|
|
1238
1255
|
const isDev = process.env.NODE_ENV === 'development';
|
|
1256
|
+
|
|
1257
|
+
// 创建 customAssets 数组用于收集自定义资产(如从 HTML 内联 script 提取的代码)
|
|
1258
|
+
const customAssets = [];
|
|
1259
|
+
|
|
1239
1260
|
await extractArkMetaJson({
|
|
1240
1261
|
...useExtractOptions,
|
|
1241
1262
|
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
1242
1263
|
isDev: isDev,
|
|
1243
|
-
compilation: compilation
|
|
1264
|
+
compilation: compilation,
|
|
1265
|
+
customAssets: customAssets
|
|
1244
1266
|
});
|
|
1245
1267
|
|
|
1246
1268
|
return Promise.resolve();
|
|
@@ -582,7 +582,7 @@
|
|
|
582
582
|
* @param {IInnerFillAssetListOptions} options
|
|
583
583
|
*/
|
|
584
584
|
async function writeInnerText(childDom, fileType, options) {
|
|
585
|
-
const { homePage, buildDirFullPath } = options;
|
|
585
|
+
const { homePage, buildDirFullPath, compilation, customAssets = [] } = options;
|
|
586
586
|
const innerText = getInnerText(childDom);
|
|
587
587
|
if (!innerText) return '';
|
|
588
588
|
|
|
@@ -592,7 +592,24 @@
|
|
|
592
592
|
const fileAbsolutePath = `${buildDirFullPath}/${scriptName}`;
|
|
593
593
|
const fileWebPath = `${slash.noEnd(homePage)}/${scriptName}`;
|
|
594
594
|
|
|
595
|
-
|
|
595
|
+
// 在开发模式下,使用 compilation.emitAsset 确保文件能被 dev server 访问
|
|
596
|
+
if (compilation && compilation.emitAsset) {
|
|
597
|
+
const { sources } = compilation.compiler.webpack;
|
|
598
|
+
compilation.emitAsset(
|
|
599
|
+
scriptName,
|
|
600
|
+
new sources.RawSource(innerText)
|
|
601
|
+
);
|
|
602
|
+
verbose(`emit asset ${scriptName} via webpack compilation`);
|
|
603
|
+
} else {
|
|
604
|
+
// 生产模式或没有 compilation 对象时,直接写入文件系统
|
|
605
|
+
await writeFile(fileAbsolutePath, innerText);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// 将自定义资产信息保存到 customAssets 数组,供后续使用
|
|
609
|
+
if (customAssets) {
|
|
610
|
+
customAssets.push({ scriptName, fileWebPath, content: innerText });
|
|
611
|
+
}
|
|
612
|
+
|
|
596
613
|
verbose(`write done, the web file will be ${fileWebPath} later`);
|
|
597
614
|
return fileWebPath;
|
|
598
615
|
}
|
|
@@ -1236,11 +1253,16 @@
|
|
|
1236
1253
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1237
1254
|
// 注入环境判断脚本
|
|
1238
1255
|
const isDev = process.env.NODE_ENV === 'development';
|
|
1256
|
+
|
|
1257
|
+
// 创建 customAssets 数组用于收集自定义资产(如从 HTML 内联 script 提取的代码)
|
|
1258
|
+
const customAssets = [];
|
|
1259
|
+
|
|
1239
1260
|
await extractArkMetaJson({
|
|
1240
1261
|
...useExtractOptions,
|
|
1241
1262
|
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
1242
1263
|
isDev: isDev,
|
|
1243
|
-
compilation: compilation
|
|
1264
|
+
compilation: compilation,
|
|
1265
|
+
customAssets: customAssets
|
|
1244
1266
|
});
|
|
1245
1267
|
|
|
1246
1268
|
return Promise.resolve();
|
package/lib/index.js
CHANGED
|
@@ -587,7 +587,7 @@ function resetScriptIdx() {
|
|
|
587
587
|
* @param {IInnerFillAssetListOptions} options
|
|
588
588
|
*/
|
|
589
589
|
async function writeInnerText(childDom, fileType, options) {
|
|
590
|
-
const { homePage, buildDirFullPath } = options;
|
|
590
|
+
const { homePage, buildDirFullPath, compilation, customAssets = [] } = options;
|
|
591
591
|
const innerText = getInnerText(childDom);
|
|
592
592
|
if (!innerText) return '';
|
|
593
593
|
|
|
@@ -597,7 +597,24 @@ async function writeInnerText(childDom, fileType, options) {
|
|
|
597
597
|
const fileAbsolutePath = `${buildDirFullPath}/${scriptName}`;
|
|
598
598
|
const fileWebPath = `${slash.noEnd(homePage)}/${scriptName}`;
|
|
599
599
|
|
|
600
|
-
|
|
600
|
+
// 在开发模式下,使用 compilation.emitAsset 确保文件能被 dev server 访问
|
|
601
|
+
if (compilation && compilation.emitAsset) {
|
|
602
|
+
const { sources } = compilation.compiler.webpack;
|
|
603
|
+
compilation.emitAsset(
|
|
604
|
+
scriptName,
|
|
605
|
+
new sources.RawSource(innerText)
|
|
606
|
+
);
|
|
607
|
+
verbose(`emit asset ${scriptName} via webpack compilation`);
|
|
608
|
+
} else {
|
|
609
|
+
// 生产模式或没有 compilation 对象时,直接写入文件系统
|
|
610
|
+
await writeFile(fileAbsolutePath, innerText);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// 将自定义资产信息保存到 customAssets 数组,供后续使用
|
|
614
|
+
if (customAssets) {
|
|
615
|
+
customAssets.push({ scriptName, fileWebPath, content: innerText });
|
|
616
|
+
}
|
|
617
|
+
|
|
601
618
|
verbose(`write done, the web file will be ${fileWebPath} later`);
|
|
602
619
|
return fileWebPath;
|
|
603
620
|
}
|
|
@@ -1241,11 +1258,16 @@ class ArkWebpackPlugin {
|
|
|
1241
1258
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1242
1259
|
// 注入环境判断脚本
|
|
1243
1260
|
const isDev = process.env.NODE_ENV === 'development';
|
|
1261
|
+
|
|
1262
|
+
// 创建 customAssets 数组用于收集自定义资产(如从 HTML 内联 script 提取的代码)
|
|
1263
|
+
const customAssets = [];
|
|
1264
|
+
|
|
1244
1265
|
await extractArkMetaJson({
|
|
1245
1266
|
...useExtractOptions,
|
|
1246
1267
|
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
1247
1268
|
isDev: isDev,
|
|
1248
|
-
compilation: compilation
|
|
1269
|
+
compilation: compilation,
|
|
1270
|
+
customAssets: customAssets
|
|
1249
1271
|
});
|
|
1250
1272
|
|
|
1251
1273
|
return Promise.resolve();
|
package/package.json
CHANGED
package/src/ArkWebpackPlugin.js
CHANGED
|
@@ -93,11 +93,16 @@ export default class ArkWebpackPlugin {
|
|
|
93
93
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
94
94
|
// 注入环境判断脚本
|
|
95
95
|
const isDev = process.env.NODE_ENV === 'development';
|
|
96
|
+
|
|
97
|
+
// 创建 customAssets 数组用于收集自定义资产(如从 HTML 内联 script 提取的代码)
|
|
98
|
+
const customAssets = [];
|
|
99
|
+
|
|
96
100
|
const arkMeta = await extractArkMetaJson({
|
|
97
101
|
...useExtractOptions,
|
|
98
102
|
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
99
103
|
isDev: isDev,
|
|
100
|
-
compilation: compilation
|
|
104
|
+
compilation: compilation,
|
|
105
|
+
customAssets: customAssets
|
|
101
106
|
});
|
|
102
107
|
|
|
103
108
|
return Promise.resolve();
|
|
@@ -78,7 +78,7 @@ export function resetScriptIdx() {
|
|
|
78
78
|
* @param {IInnerFillAssetListOptions} options
|
|
79
79
|
*/
|
|
80
80
|
async function writeInnerText(childDom, fileType, options) {
|
|
81
|
-
const { homePage, buildDirFullPath } = options;
|
|
81
|
+
const { homePage, buildDirFullPath, compilation, customAssets = [] } = options;
|
|
82
82
|
const innerText = getInnerText(childDom);
|
|
83
83
|
if (!innerText) return '';
|
|
84
84
|
|
|
@@ -88,7 +88,24 @@ async function writeInnerText(childDom, fileType, options) {
|
|
|
88
88
|
const fileAbsolutePath = `${buildDirFullPath}/${scriptName}`;
|
|
89
89
|
const fileWebPath = `${slash.noEnd(homePage)}/${scriptName}`;
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
// 在开发模式下,使用 compilation.emitAsset 确保文件能被 dev server 访问
|
|
92
|
+
if (compilation && compilation.emitAsset) {
|
|
93
|
+
const { sources } = compilation.compiler.webpack;
|
|
94
|
+
compilation.emitAsset(
|
|
95
|
+
scriptName,
|
|
96
|
+
new sources.RawSource(innerText)
|
|
97
|
+
);
|
|
98
|
+
verbose(`emit asset ${scriptName} via webpack compilation`);
|
|
99
|
+
} else {
|
|
100
|
+
// 生产模式或没有 compilation 对象时,直接写入文件系统
|
|
101
|
+
await writeFile(fileAbsolutePath, innerText);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 将自定义资产信息保存到 customAssets 数组,供后续使用
|
|
105
|
+
if (customAssets) {
|
|
106
|
+
customAssets.push({ scriptName, fileWebPath, content: innerText });
|
|
107
|
+
}
|
|
108
|
+
|
|
92
109
|
verbose(`write done, the web file will be ${fileWebPath} later`);
|
|
93
110
|
return fileWebPath;
|
|
94
111
|
}
|
package/typings.d.ts
CHANGED
|
@@ -235,6 +235,10 @@ export interface IInnerFillAssetListOptions {
|
|
|
235
235
|
enableRelativePath: IUserExtractOptions['enableRelativePath'];
|
|
236
236
|
enablePrefixHomePage: IUserExtractOptions['enablePrefixHomePage'];
|
|
237
237
|
enableAssetInnerText: IUserExtractOptions['enableAssetInnerText'];
|
|
238
|
+
/** webpack compilation 对象,用于在开发模式下通过 emitAsset 输出文件 */
|
|
239
|
+
compilation?: any;
|
|
240
|
+
/** 自定义资产列表,用于收集从 HTML 内联脚本提取的代码 */
|
|
241
|
+
customAssets?: Array<{ scriptName: string; fileWebPath: string; content: string }>;
|
|
238
242
|
}
|
|
239
243
|
|
|
240
244
|
export interface ICreateSubAppOptions {
|