@arkxio/ark-dev-utils 0.1.0 → 0.1.2
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 +30 -18
- package/dist/ark-dev-utils.min.js +30 -18
- package/lib/index.js +30 -18
- package/package.json +1 -1
- package/src/ArkWebpackPlugin.js +7 -13
- package/src/configs/externalsDefault.js +2 -0
- package/src/meta-extractor/fillAssetList.js +6 -0
- package/src/meta-extractor/index.js +16 -5
package/dist/ark-dev-utils.js
CHANGED
|
@@ -568,8 +568,14 @@
|
|
|
568
568
|
return assetItem;
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
// 注意:这个变量需要在每次编译时重置
|
|
572
|
+
// 不在这里维护,而是通过 options 传递
|
|
571
573
|
let custScriptIdx = 0;
|
|
572
574
|
|
|
575
|
+
function resetScriptIdx() {
|
|
576
|
+
custScriptIdx = 0;
|
|
577
|
+
}
|
|
578
|
+
|
|
573
579
|
/**
|
|
574
580
|
* @param {HTMLScriptElement | HTMLStyleElement} childDom
|
|
575
581
|
* @param {string} fileType
|
|
@@ -965,11 +971,22 @@
|
|
|
965
971
|
verbose('[begin] write memory ark meta ' + metaFilename);
|
|
966
972
|
|
|
967
973
|
const metaContent = JSON.stringify(arkMeta, null, 2);
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
974
|
+
const compilation = userExtractOptions.compilation;
|
|
975
|
+
|
|
976
|
+
// Webpack 5 正确的 API:使用 emitAsset
|
|
977
|
+
if (compilation.emitAsset) {
|
|
978
|
+
const { sources } = compilation.compiler.webpack;
|
|
979
|
+
compilation.emitAsset(
|
|
980
|
+
metaFilename,
|
|
981
|
+
new sources.RawSource(metaContent)
|
|
982
|
+
);
|
|
983
|
+
} else {
|
|
984
|
+
// Webpack 4 兼容
|
|
985
|
+
compilation.assets[metaFilename] = {
|
|
986
|
+
source: () => metaContent,
|
|
987
|
+
size: () => metaContent.length
|
|
988
|
+
};
|
|
989
|
+
}
|
|
973
990
|
verbose('[finish] write memory ark meta ' + metaFilename);
|
|
974
991
|
}else if (writeMetaJsonToDist) {
|
|
975
992
|
// 生产模式:写入物理文件
|
|
@@ -1119,6 +1136,8 @@
|
|
|
1119
1136
|
'@arkxio/ark-micro-core': 'ArkMicroCore',
|
|
1120
1137
|
'@arkxio/ark-lib-proxy': 'ArkLibProxy',
|
|
1121
1138
|
'@arkxio/ark-micro': 'ArkMicro',
|
|
1139
|
+
// 'echarts': 'echarts',
|
|
1140
|
+
// 'tinymce': 'tinymce'
|
|
1122
1141
|
// "loadjs": { //将vue依赖 "外部化",不打包进组件库
|
|
1123
1142
|
// root: 'loadjs',
|
|
1124
1143
|
// commonjs: 'loadjs',
|
|
@@ -1139,6 +1158,11 @@
|
|
|
1139
1158
|
compiler.context;
|
|
1140
1159
|
const useExtractOptions = this.metaOptions;
|
|
1141
1160
|
|
|
1161
|
+
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1162
|
+
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1163
|
+
resetScriptIdx();
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1142
1166
|
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1143
1167
|
compilation.hooks.processAssets.tap(
|
|
1144
1168
|
{
|
|
@@ -1210,23 +1234,11 @@
|
|
|
1210
1234
|
});
|
|
1211
1235
|
|
|
1212
1236
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1213
|
-
const assets = compilation.assets;
|
|
1214
|
-
const outputPath = compilation.options.output.publicPath;
|
|
1215
|
-
const jsFiles = [];
|
|
1216
|
-
Object.keys(assets).forEach((assetName) => {
|
|
1217
|
-
if (assetName.endsWith('.js')) {
|
|
1218
|
-
console.log('Final JS file:', assetName);
|
|
1219
|
-
if (assetName.indexOf('js/app.') !== -1) {
|
|
1220
|
-
jsFiles.push(outputPath + assetName);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
});
|
|
1224
|
-
|
|
1225
1237
|
// 注入环境判断脚本
|
|
1226
1238
|
const isDev = process.env.NODE_ENV === 'development';
|
|
1227
1239
|
await extractArkMetaJson({
|
|
1228
1240
|
...useExtractOptions,
|
|
1229
|
-
chunkJsFiles
|
|
1241
|
+
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
1230
1242
|
isDev: isDev,
|
|
1231
1243
|
compilation: compilation
|
|
1232
1244
|
});
|
|
@@ -568,8 +568,14 @@
|
|
|
568
568
|
return assetItem;
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
// 注意:这个变量需要在每次编译时重置
|
|
572
|
+
// 不在这里维护,而是通过 options 传递
|
|
571
573
|
let custScriptIdx = 0;
|
|
572
574
|
|
|
575
|
+
function resetScriptIdx() {
|
|
576
|
+
custScriptIdx = 0;
|
|
577
|
+
}
|
|
578
|
+
|
|
573
579
|
/**
|
|
574
580
|
* @param {HTMLScriptElement | HTMLStyleElement} childDom
|
|
575
581
|
* @param {string} fileType
|
|
@@ -965,11 +971,22 @@
|
|
|
965
971
|
verbose('[begin] write memory ark meta ' + metaFilename);
|
|
966
972
|
|
|
967
973
|
const metaContent = JSON.stringify(arkMeta, null, 2);
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
974
|
+
const compilation = userExtractOptions.compilation;
|
|
975
|
+
|
|
976
|
+
// Webpack 5 正确的 API:使用 emitAsset
|
|
977
|
+
if (compilation.emitAsset) {
|
|
978
|
+
const { sources } = compilation.compiler.webpack;
|
|
979
|
+
compilation.emitAsset(
|
|
980
|
+
metaFilename,
|
|
981
|
+
new sources.RawSource(metaContent)
|
|
982
|
+
);
|
|
983
|
+
} else {
|
|
984
|
+
// Webpack 4 兼容
|
|
985
|
+
compilation.assets[metaFilename] = {
|
|
986
|
+
source: () => metaContent,
|
|
987
|
+
size: () => metaContent.length
|
|
988
|
+
};
|
|
989
|
+
}
|
|
973
990
|
verbose('[finish] write memory ark meta ' + metaFilename);
|
|
974
991
|
}else if (writeMetaJsonToDist) {
|
|
975
992
|
// 生产模式:写入物理文件
|
|
@@ -1119,6 +1136,8 @@
|
|
|
1119
1136
|
'@arkxio/ark-micro-core': 'ArkMicroCore',
|
|
1120
1137
|
'@arkxio/ark-lib-proxy': 'ArkLibProxy',
|
|
1121
1138
|
'@arkxio/ark-micro': 'ArkMicro',
|
|
1139
|
+
// 'echarts': 'echarts',
|
|
1140
|
+
// 'tinymce': 'tinymce'
|
|
1122
1141
|
// "loadjs": { //将vue依赖 "外部化",不打包进组件库
|
|
1123
1142
|
// root: 'loadjs',
|
|
1124
1143
|
// commonjs: 'loadjs',
|
|
@@ -1139,6 +1158,11 @@
|
|
|
1139
1158
|
compiler.context;
|
|
1140
1159
|
const useExtractOptions = this.metaOptions;
|
|
1141
1160
|
|
|
1161
|
+
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1162
|
+
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1163
|
+
resetScriptIdx();
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1142
1166
|
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1143
1167
|
compilation.hooks.processAssets.tap(
|
|
1144
1168
|
{
|
|
@@ -1210,23 +1234,11 @@
|
|
|
1210
1234
|
});
|
|
1211
1235
|
|
|
1212
1236
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1213
|
-
const assets = compilation.assets;
|
|
1214
|
-
const outputPath = compilation.options.output.publicPath;
|
|
1215
|
-
const jsFiles = [];
|
|
1216
|
-
Object.keys(assets).forEach((assetName) => {
|
|
1217
|
-
if (assetName.endsWith('.js')) {
|
|
1218
|
-
console.log('Final JS file:', assetName);
|
|
1219
|
-
if (assetName.indexOf('js/app.') !== -1) {
|
|
1220
|
-
jsFiles.push(outputPath + assetName);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
});
|
|
1224
|
-
|
|
1225
1237
|
// 注入环境判断脚本
|
|
1226
1238
|
const isDev = process.env.NODE_ENV === 'development';
|
|
1227
1239
|
await extractArkMetaJson({
|
|
1228
1240
|
...useExtractOptions,
|
|
1229
|
-
chunkJsFiles
|
|
1241
|
+
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
1230
1242
|
isDev: isDev,
|
|
1231
1243
|
compilation: compilation
|
|
1232
1244
|
});
|
package/lib/index.js
CHANGED
|
@@ -573,8 +573,14 @@ function buildAssetItem(tag, /** @type {IAssetInfo} */ assetInfo) {
|
|
|
573
573
|
return assetItem;
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
+
// 注意:这个变量需要在每次编译时重置
|
|
577
|
+
// 不在这里维护,而是通过 options 传递
|
|
576
578
|
let custScriptIdx = 0;
|
|
577
579
|
|
|
580
|
+
function resetScriptIdx() {
|
|
581
|
+
custScriptIdx = 0;
|
|
582
|
+
}
|
|
583
|
+
|
|
578
584
|
/**
|
|
579
585
|
* @param {HTMLScriptElement | HTMLStyleElement} childDom
|
|
580
586
|
* @param {string} fileType
|
|
@@ -970,11 +976,22 @@ async function extractArkMetaJson(userExtractOptions) {
|
|
|
970
976
|
verbose('[begin] write memory ark meta ' + metaFilename);
|
|
971
977
|
|
|
972
978
|
const metaContent = JSON.stringify(arkMeta, null, 2);
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
979
|
+
const compilation = userExtractOptions.compilation;
|
|
980
|
+
|
|
981
|
+
// Webpack 5 正确的 API:使用 emitAsset
|
|
982
|
+
if (compilation.emitAsset) {
|
|
983
|
+
const { sources } = compilation.compiler.webpack;
|
|
984
|
+
compilation.emitAsset(
|
|
985
|
+
metaFilename,
|
|
986
|
+
new sources.RawSource(metaContent)
|
|
987
|
+
);
|
|
988
|
+
} else {
|
|
989
|
+
// Webpack 4 兼容
|
|
990
|
+
compilation.assets[metaFilename] = {
|
|
991
|
+
source: () => metaContent,
|
|
992
|
+
size: () => metaContent.length
|
|
993
|
+
};
|
|
994
|
+
}
|
|
978
995
|
verbose('[finish] write memory ark meta ' + metaFilename);
|
|
979
996
|
}else if (writeMetaJsonToDist) {
|
|
980
997
|
// 生产模式:写入物理文件
|
|
@@ -1124,6 +1141,8 @@ var ExternalsDefault = {
|
|
|
1124
1141
|
'@arkxio/ark-micro-core': 'ArkMicroCore',
|
|
1125
1142
|
'@arkxio/ark-lib-proxy': 'ArkLibProxy',
|
|
1126
1143
|
'@arkxio/ark-micro': 'ArkMicro',
|
|
1144
|
+
// 'echarts': 'echarts',
|
|
1145
|
+
// 'tinymce': 'tinymce'
|
|
1127
1146
|
// "loadjs": { //将vue依赖 "外部化",不打包进组件库
|
|
1128
1147
|
// root: 'loadjs',
|
|
1129
1148
|
// commonjs: 'loadjs',
|
|
@@ -1144,6 +1163,11 @@ class ArkWebpackPlugin {
|
|
|
1144
1163
|
compiler.context;
|
|
1145
1164
|
const useExtractOptions = this.metaOptions;
|
|
1146
1165
|
|
|
1166
|
+
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
1167
|
+
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
1168
|
+
resetScriptIdx();
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1147
1171
|
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
1148
1172
|
compilation.hooks.processAssets.tap(
|
|
1149
1173
|
{
|
|
@@ -1215,23 +1239,11 @@ class ArkWebpackPlugin {
|
|
|
1215
1239
|
});
|
|
1216
1240
|
|
|
1217
1241
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
1218
|
-
const assets = compilation.assets;
|
|
1219
|
-
const outputPath = compilation.options.output.publicPath;
|
|
1220
|
-
const jsFiles = [];
|
|
1221
|
-
Object.keys(assets).forEach((assetName) => {
|
|
1222
|
-
if (assetName.endsWith('.js')) {
|
|
1223
|
-
console.log('Final JS file:', assetName);
|
|
1224
|
-
if (assetName.indexOf('js/app.') !== -1) {
|
|
1225
|
-
jsFiles.push(outputPath + assetName);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
1242
|
// 注入环境判断脚本
|
|
1231
1243
|
const isDev = process.env.NODE_ENV === 'development';
|
|
1232
1244
|
await extractArkMetaJson({
|
|
1233
1245
|
...useExtractOptions,
|
|
1234
|
-
chunkJsFiles
|
|
1246
|
+
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
1235
1247
|
isDev: isDev,
|
|
1236
1248
|
compilation: compilation
|
|
1237
1249
|
});
|
package/package.json
CHANGED
package/src/ArkWebpackPlugin.js
CHANGED
|
@@ -2,6 +2,7 @@ import path from "path";
|
|
|
2
2
|
import extractArkMetaJson from './meta-extractor/index';
|
|
3
3
|
import {verbose} from "./inner-utils";
|
|
4
4
|
import { Compilation } from 'webpack';
|
|
5
|
+
import { resetScriptIdx } from './meta-extractor/fillAssetList';
|
|
5
6
|
|
|
6
7
|
export default class ArkWebpackPlugin {
|
|
7
8
|
|
|
@@ -14,6 +15,11 @@ export default class ArkWebpackPlugin {
|
|
|
14
15
|
const projectRoot = compiler.context;
|
|
15
16
|
const useExtractOptions = this.metaOptions;
|
|
16
17
|
|
|
18
|
+
// 在每次编译开始时重置脚本索引计数器,确保文件名一致性
|
|
19
|
+
compiler.hooks.thisCompilation.tap('ArkResetScriptIdx', () => {
|
|
20
|
+
resetScriptIdx();
|
|
21
|
+
});
|
|
22
|
+
|
|
17
23
|
compiler.hooks.thisCompilation.tap('ArkDynamicCdnChunkLoaderPlugin', (compilation) => {
|
|
18
24
|
compilation.hooks.processAssets.tap(
|
|
19
25
|
{
|
|
@@ -85,23 +91,11 @@ export default class ArkWebpackPlugin {
|
|
|
85
91
|
});
|
|
86
92
|
|
|
87
93
|
compiler.hooks.emit.tapPromise('ArkMetaJsonGeneratorPlugin', async (compilation) => {
|
|
88
|
-
const assets = compilation.assets;
|
|
89
|
-
const outputPath = compilation.options.output.publicPath;
|
|
90
|
-
const jsFiles = []
|
|
91
|
-
Object.keys(assets).forEach((assetName) => {
|
|
92
|
-
if (assetName.endsWith('.js')) {
|
|
93
|
-
console.log('Final JS file:', assetName);
|
|
94
|
-
if (assetName.indexOf('js/app.') !== -1) {
|
|
95
|
-
jsFiles.push(outputPath + assetName);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
94
|
// 注入环境判断脚本
|
|
101
95
|
const isDev = process.env.NODE_ENV === 'development';
|
|
102
96
|
const arkMeta = await extractArkMetaJson({
|
|
103
97
|
...useExtractOptions,
|
|
104
|
-
chunkJsFiles
|
|
98
|
+
// chunkJsFiles 将从 HTML 中的内联 script 提取,不需要在这里传递
|
|
105
99
|
isDev: isDev,
|
|
106
100
|
compilation: compilation
|
|
107
101
|
});
|
|
@@ -12,6 +12,8 @@ export default {
|
|
|
12
12
|
'@arkxio/ark-micro-core': 'ArkMicroCore',
|
|
13
13
|
'@arkxio/ark-lib-proxy': 'ArkLibProxy',
|
|
14
14
|
'@arkxio/ark-micro': 'ArkMicro',
|
|
15
|
+
// 'echarts': 'echarts',
|
|
16
|
+
// 'tinymce': 'tinymce'
|
|
15
17
|
// "loadjs": { //将vue依赖 "外部化",不打包进组件库
|
|
16
18
|
// root: 'loadjs',
|
|
17
19
|
// commonjs: 'loadjs',
|
|
@@ -64,8 +64,14 @@ function buildAssetItem(tag, /** @type {IAssetInfo} */ assetInfo) {
|
|
|
64
64
|
return assetItem;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// 注意:这个变量需要在每次编译时重置
|
|
68
|
+
// 不在这里维护,而是通过 options 传递
|
|
67
69
|
let custScriptIdx = 0;
|
|
68
70
|
|
|
71
|
+
export function resetScriptIdx() {
|
|
72
|
+
custScriptIdx = 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
/**
|
|
70
76
|
* @param {HTMLScriptElement | HTMLStyleElement} childDom
|
|
71
77
|
* @param {string} fileType
|
|
@@ -56,11 +56,22 @@ export default async function extractArkMetaJson(userExtractOptions) {
|
|
|
56
56
|
verbose('[begin] write memory ark meta ' + metaFilename)
|
|
57
57
|
|
|
58
58
|
const metaContent = JSON.stringify(arkMeta, null, 2);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const compilation = userExtractOptions.compilation;
|
|
60
|
+
|
|
61
|
+
// Webpack 5 正确的 API:使用 emitAsset
|
|
62
|
+
if (compilation.emitAsset) {
|
|
63
|
+
const { sources } = compilation.compiler.webpack;
|
|
64
|
+
compilation.emitAsset(
|
|
65
|
+
metaFilename,
|
|
66
|
+
new sources.RawSource(metaContent)
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
// Webpack 4 兼容
|
|
70
|
+
compilation.assets[metaFilename] = {
|
|
71
|
+
source: () => metaContent,
|
|
72
|
+
size: () => metaContent.length
|
|
73
|
+
};
|
|
74
|
+
}
|
|
64
75
|
verbose('[finish] write memory ark meta ' + metaFilename)
|
|
65
76
|
}else if (writeMetaJsonToDist) {
|
|
66
77
|
// 生产模式:写入物理文件
|