@pedrolamas/plugin-vue2 2.4.0 → 2.4.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +142 -77
- package/dist/index.mjs +143 -78
- package/package.json +8 -6
package/dist/index.cjs
CHANGED
|
@@ -14,6 +14,48 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
14
14
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
15
15
|
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
16
16
|
|
|
17
|
+
//#region src/utils.ts
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/filter/simple-filters.ts
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a RegExp that matches the exact string specified.
|
|
22
|
+
*
|
|
23
|
+
* This is useful for plugin hook filters.
|
|
24
|
+
*
|
|
25
|
+
* @param str the string to match.
|
|
26
|
+
* @param flags flags for the RegExp.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
31
|
+
* const plugin = {
|
|
32
|
+
* name: 'plugin',
|
|
33
|
+
* resolveId: {
|
|
34
|
+
* filter: { id: exactRegex('foo') },
|
|
35
|
+
* handler(id) {} // will only be called for `foo`
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function exactRegex(str, flags) {
|
|
41
|
+
return new RegExp(`^${escapeRegex(str)}$`, flags);
|
|
42
|
+
}
|
|
43
|
+
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
|
|
44
|
+
function escapeRegex(str) {
|
|
45
|
+
return str.replace(escapeRegexRE, "\\$&");
|
|
46
|
+
}
|
|
47
|
+
function makeIdFiltersToMatchWithQuery(input) {
|
|
48
|
+
if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
|
|
49
|
+
return input.map((i) => makeIdFilterToMatchWithQuery(i));
|
|
50
|
+
}
|
|
51
|
+
function makeIdFilterToMatchWithQuery(input) {
|
|
52
|
+
if (typeof input === "string") return `${input}{?*,}`;
|
|
53
|
+
return makeRegexIdFilterToMatchWithQuery(input);
|
|
54
|
+
}
|
|
55
|
+
function makeRegexIdFilterToMatchWithQuery(input) {
|
|
56
|
+
return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
|
|
57
|
+
}
|
|
58
|
+
|
|
17
59
|
function resolveCompiler(root) {
|
|
18
60
|
const compiler = tryRequire("vue/compiler-sfc", root) || tryRequire("vue/compiler-sfc");
|
|
19
61
|
if (!compiler) {
|
|
@@ -878,7 +920,9 @@ var __component__ = /*#__PURE__*/__normalizer(
|
|
|
878
920
|
output.push(`export default __component__.exports`);
|
|
879
921
|
let resolvedCode = output.join("\n");
|
|
880
922
|
if ((descriptor.script?.lang === "ts" || descriptor.scriptSetup?.lang === "ts") && !descriptor.script?.src) {
|
|
881
|
-
|
|
923
|
+
if (resolvedMap) {
|
|
924
|
+
resolvedMap = { ...resolvedMap, file: resolvedMap.file ?? filename };
|
|
925
|
+
}
|
|
882
926
|
const { code: code2, map } = await vite.transformWithOxc(
|
|
883
927
|
resolvedCode,
|
|
884
928
|
filename,
|
|
@@ -895,11 +939,6 @@ var __component__ = /*#__PURE__*/__normalizer(
|
|
|
895
939
|
code: resolvedCode,
|
|
896
940
|
map: resolvedMap || {
|
|
897
941
|
mappings: ""
|
|
898
|
-
},
|
|
899
|
-
meta: {
|
|
900
|
-
vite: {
|
|
901
|
-
lang: descriptor.script?.lang || descriptor.scriptSetup?.lang || "js"
|
|
902
|
-
}
|
|
903
942
|
}
|
|
904
943
|
};
|
|
905
944
|
}
|
|
@@ -1108,7 +1147,11 @@ async function transformStyle(code, descriptor, index, options, pluginContext, f
|
|
|
1108
1147
|
) : { mappings: "" };
|
|
1109
1148
|
return {
|
|
1110
1149
|
code: result.code,
|
|
1111
|
-
map
|
|
1150
|
+
map,
|
|
1151
|
+
// upstream @vitejs/plugin-vue also excludes temp descriptors here (cssScopeTo
|
|
1152
|
+
// would point at the wrong module); not needed here since getSrcDescriptor
|
|
1153
|
+
// has no temp-descriptor fallback, it always resolves the real owning file
|
|
1154
|
+
meta: block.scoped ? { vite: { cssScopeTo: [descriptor.filename, "default"] } } : void 0
|
|
1112
1155
|
};
|
|
1113
1156
|
}
|
|
1114
1157
|
function getLine(source, start) {
|
|
@@ -1122,6 +1165,9 @@ function getLine(source, start) {
|
|
|
1122
1165
|
}
|
|
1123
1166
|
}
|
|
1124
1167
|
|
|
1168
|
+
function toArray(value) {
|
|
1169
|
+
return value == null ? [] : Array.isArray(value) ? value : [value];
|
|
1170
|
+
}
|
|
1125
1171
|
function vuePlugin(rawOptions = {}) {
|
|
1126
1172
|
const {
|
|
1127
1173
|
include = /\.vue$/,
|
|
@@ -1130,6 +1176,12 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1130
1176
|
// reactivityTransform = false
|
|
1131
1177
|
} = rawOptions;
|
|
1132
1178
|
const filter = vite.createFilter(include, exclude);
|
|
1179
|
+
const vueQueryFilter = /[?&]vue\b/;
|
|
1180
|
+
const idFilter = [exactRegex(NORMALIZER_ID), exactRegex(HMR_RUNTIME_ID), vueQueryFilter];
|
|
1181
|
+
const transformIdFilter = {
|
|
1182
|
+
include: [...makeIdFiltersToMatchWithQuery(toArray(include)), vueQueryFilter],
|
|
1183
|
+
exclude: exclude ? makeIdFiltersToMatchWithQuery(toArray(exclude)) : void 0
|
|
1184
|
+
};
|
|
1133
1185
|
let options = {
|
|
1134
1186
|
isProduction: process.env.NODE_ENV === "production",
|
|
1135
1187
|
compiler: null,
|
|
@@ -1152,6 +1204,16 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1152
1204
|
}
|
|
1153
1205
|
return handleHotUpdate(ctx, options);
|
|
1154
1206
|
},
|
|
1207
|
+
config(config) {
|
|
1208
|
+
return {
|
|
1209
|
+
resolve: {
|
|
1210
|
+
alias: vite.mergeAlias(
|
|
1211
|
+
[{ find: "vue", replacement: "vue/dist/vue.runtime.esm.js" }],
|
|
1212
|
+
config.resolve?.alias
|
|
1213
|
+
)
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
},
|
|
1155
1217
|
configResolved(config) {
|
|
1156
1218
|
options = {
|
|
1157
1219
|
...options,
|
|
@@ -1161,12 +1223,6 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1161
1223
|
cssDevSourcemap: config.css?.devSourcemap ?? false,
|
|
1162
1224
|
devToolsEnabled: !config.isProduction
|
|
1163
1225
|
};
|
|
1164
|
-
if (!config.resolve.alias.some(({ find }) => find === "vue")) {
|
|
1165
|
-
config.resolve.alias.push({
|
|
1166
|
-
find: "vue",
|
|
1167
|
-
replacement: "vue/dist/vue.runtime.esm.js"
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
1226
|
},
|
|
1171
1227
|
configureServer(server) {
|
|
1172
1228
|
options.devServer = server;
|
|
@@ -1174,81 +1230,90 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1174
1230
|
buildStart() {
|
|
1175
1231
|
options.compiler = options.compiler || resolveCompiler(options.root);
|
|
1176
1232
|
},
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1233
|
+
resolveId: {
|
|
1234
|
+
filter: { id: idFilter },
|
|
1235
|
+
async handler(id) {
|
|
1236
|
+
if (id === NORMALIZER_ID || id === HMR_RUNTIME_ID) {
|
|
1237
|
+
return id;
|
|
1238
|
+
}
|
|
1239
|
+
if (parseVueRequest(id).query.vue) {
|
|
1240
|
+
return id;
|
|
1241
|
+
}
|
|
1183
1242
|
}
|
|
1184
1243
|
},
|
|
1185
|
-
load
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
return hmrRuntimeCode;
|
|
1192
|
-
}
|
|
1193
|
-
const { filename, query } = parseVueRequest(id);
|
|
1194
|
-
if (query.vue) {
|
|
1195
|
-
if (query.src) {
|
|
1196
|
-
return fs__default.readFileSync(filename, "utf-8");
|
|
1244
|
+
load: {
|
|
1245
|
+
filter: { id: idFilter },
|
|
1246
|
+
handler(id, opt) {
|
|
1247
|
+
const ssr = opt?.ssr === true;
|
|
1248
|
+
if (id === NORMALIZER_ID) {
|
|
1249
|
+
return normalizerCode;
|
|
1197
1250
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
if (query.type === "script") {
|
|
1201
|
-
block = getResolvedScript(descriptor, ssr);
|
|
1202
|
-
} else if (query.type === "template") {
|
|
1203
|
-
block = descriptor.template;
|
|
1204
|
-
} else if (query.type === "style") {
|
|
1205
|
-
block = descriptor.styles[query.index];
|
|
1206
|
-
} else if (query.index != null) {
|
|
1207
|
-
block = descriptor.customBlocks[query.index];
|
|
1251
|
+
if (id === HMR_RUNTIME_ID) {
|
|
1252
|
+
return hmrRuntimeCode;
|
|
1208
1253
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
}
|
|
1254
|
+
const { filename, query } = parseVueRequest(id);
|
|
1255
|
+
if (query.vue) {
|
|
1256
|
+
if (query.src) {
|
|
1257
|
+
return fs__default.readFileSync(filename, "utf-8");
|
|
1258
|
+
}
|
|
1259
|
+
const descriptor = getDescriptor(filename, options);
|
|
1260
|
+
let block;
|
|
1261
|
+
if (query.type === "script") {
|
|
1262
|
+
block = getResolvedScript(descriptor, ssr);
|
|
1263
|
+
} else if (query.type === "template") {
|
|
1264
|
+
block = descriptor.template;
|
|
1265
|
+
} else if (query.type === "style") {
|
|
1266
|
+
block = descriptor.styles[query.index];
|
|
1267
|
+
} else if (query.index != null) {
|
|
1268
|
+
block = descriptor.customBlocks[query.index];
|
|
1269
|
+
}
|
|
1270
|
+
if (block) {
|
|
1271
|
+
return {
|
|
1272
|
+
code: block.content,
|
|
1273
|
+
map: block.map
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1214
1276
|
}
|
|
1215
1277
|
}
|
|
1216
1278
|
},
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1279
|
+
transform: {
|
|
1280
|
+
filter: { id: transformIdFilter },
|
|
1281
|
+
async handler(code, id, opt) {
|
|
1282
|
+
const ssr = opt?.ssr === true;
|
|
1283
|
+
const { filename, query } = parseVueRequest(id);
|
|
1284
|
+
if (query.raw) {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
if (!filter(filename) && !query.vue) {
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
if (!query.vue) {
|
|
1291
|
+
return transformMain(code, filename, options, this, ssr);
|
|
1292
|
+
} else {
|
|
1293
|
+
const descriptor = query.src ? getSrcDescriptor(filename, query) : getDescriptor(filename, options);
|
|
1294
|
+
if (query.type === "template") {
|
|
1295
|
+
return {
|
|
1296
|
+
code: await transformTemplateAsModule(
|
|
1297
|
+
code,
|
|
1298
|
+
descriptor,
|
|
1299
|
+
options,
|
|
1300
|
+
this,
|
|
1301
|
+
ssr
|
|
1302
|
+
),
|
|
1303
|
+
map: {
|
|
1304
|
+
mappings: ""
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
} else if (query.type === "style") {
|
|
1308
|
+
return transformStyle(
|
|
1233
1309
|
code,
|
|
1234
1310
|
descriptor,
|
|
1311
|
+
Number(query.index),
|
|
1235
1312
|
options,
|
|
1236
1313
|
this,
|
|
1237
|
-
|
|
1238
|
-
)
|
|
1239
|
-
|
|
1240
|
-
mappings: ""
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
} else if (query.type === "style") {
|
|
1244
|
-
return transformStyle(
|
|
1245
|
-
code,
|
|
1246
|
-
descriptor,
|
|
1247
|
-
Number(query.index),
|
|
1248
|
-
options,
|
|
1249
|
-
this,
|
|
1250
|
-
filename
|
|
1251
|
-
);
|
|
1314
|
+
filename
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1252
1317
|
}
|
|
1253
1318
|
}
|
|
1254
1319
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,51 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import { transformWithOxc, formatPostcssSourceMap, createFilter } from 'vite';
|
|
2
|
+
import { transformWithOxc, formatPostcssSourceMap, createFilter, mergeAlias } from 'vite';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
6
|
|
|
7
|
+
//#region src/utils.ts
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/filter/simple-filters.ts
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a RegExp that matches the exact string specified.
|
|
12
|
+
*
|
|
13
|
+
* This is useful for plugin hook filters.
|
|
14
|
+
*
|
|
15
|
+
* @param str the string to match.
|
|
16
|
+
* @param flags flags for the RegExp.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
21
|
+
* const plugin = {
|
|
22
|
+
* name: 'plugin',
|
|
23
|
+
* resolveId: {
|
|
24
|
+
* filter: { id: exactRegex('foo') },
|
|
25
|
+
* handler(id) {} // will only be called for `foo`
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function exactRegex(str, flags) {
|
|
31
|
+
return new RegExp(`^${escapeRegex(str)}$`, flags);
|
|
32
|
+
}
|
|
33
|
+
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
|
|
34
|
+
function escapeRegex(str) {
|
|
35
|
+
return str.replace(escapeRegexRE, "\\$&");
|
|
36
|
+
}
|
|
37
|
+
function makeIdFiltersToMatchWithQuery(input) {
|
|
38
|
+
if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
|
|
39
|
+
return input.map((i) => makeIdFilterToMatchWithQuery(i));
|
|
40
|
+
}
|
|
41
|
+
function makeIdFilterToMatchWithQuery(input) {
|
|
42
|
+
if (typeof input === "string") return `${input}{?*,}`;
|
|
43
|
+
return makeRegexIdFilterToMatchWithQuery(input);
|
|
44
|
+
}
|
|
45
|
+
function makeRegexIdFilterToMatchWithQuery(input) {
|
|
46
|
+
return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
|
|
47
|
+
}
|
|
48
|
+
|
|
7
49
|
function resolveCompiler(root) {
|
|
8
50
|
const compiler = tryRequire("vue/compiler-sfc", root) || tryRequire("vue/compiler-sfc");
|
|
9
51
|
if (!compiler) {
|
|
@@ -868,7 +910,9 @@ var __component__ = /*#__PURE__*/__normalizer(
|
|
|
868
910
|
output.push(`export default __component__.exports`);
|
|
869
911
|
let resolvedCode = output.join("\n");
|
|
870
912
|
if ((descriptor.script?.lang === "ts" || descriptor.scriptSetup?.lang === "ts") && !descriptor.script?.src) {
|
|
871
|
-
|
|
913
|
+
if (resolvedMap) {
|
|
914
|
+
resolvedMap = { ...resolvedMap, file: resolvedMap.file ?? filename };
|
|
915
|
+
}
|
|
872
916
|
const { code: code2, map } = await transformWithOxc(
|
|
873
917
|
resolvedCode,
|
|
874
918
|
filename,
|
|
@@ -885,11 +929,6 @@ var __component__ = /*#__PURE__*/__normalizer(
|
|
|
885
929
|
code: resolvedCode,
|
|
886
930
|
map: resolvedMap || {
|
|
887
931
|
mappings: ""
|
|
888
|
-
},
|
|
889
|
-
meta: {
|
|
890
|
-
vite: {
|
|
891
|
-
lang: descriptor.script?.lang || descriptor.scriptSetup?.lang || "js"
|
|
892
|
-
}
|
|
893
932
|
}
|
|
894
933
|
};
|
|
895
934
|
}
|
|
@@ -1098,7 +1137,11 @@ async function transformStyle(code, descriptor, index, options, pluginContext, f
|
|
|
1098
1137
|
) : { mappings: "" };
|
|
1099
1138
|
return {
|
|
1100
1139
|
code: result.code,
|
|
1101
|
-
map
|
|
1140
|
+
map,
|
|
1141
|
+
// upstream @vitejs/plugin-vue also excludes temp descriptors here (cssScopeTo
|
|
1142
|
+
// would point at the wrong module); not needed here since getSrcDescriptor
|
|
1143
|
+
// has no temp-descriptor fallback, it always resolves the real owning file
|
|
1144
|
+
meta: block.scoped ? { vite: { cssScopeTo: [descriptor.filename, "default"] } } : void 0
|
|
1102
1145
|
};
|
|
1103
1146
|
}
|
|
1104
1147
|
function getLine(source, start) {
|
|
@@ -1112,6 +1155,9 @@ function getLine(source, start) {
|
|
|
1112
1155
|
}
|
|
1113
1156
|
}
|
|
1114
1157
|
|
|
1158
|
+
function toArray(value) {
|
|
1159
|
+
return value == null ? [] : Array.isArray(value) ? value : [value];
|
|
1160
|
+
}
|
|
1115
1161
|
function vuePlugin(rawOptions = {}) {
|
|
1116
1162
|
const {
|
|
1117
1163
|
include = /\.vue$/,
|
|
@@ -1120,6 +1166,12 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1120
1166
|
// reactivityTransform = false
|
|
1121
1167
|
} = rawOptions;
|
|
1122
1168
|
const filter = createFilter(include, exclude);
|
|
1169
|
+
const vueQueryFilter = /[?&]vue\b/;
|
|
1170
|
+
const idFilter = [exactRegex(NORMALIZER_ID), exactRegex(HMR_RUNTIME_ID), vueQueryFilter];
|
|
1171
|
+
const transformIdFilter = {
|
|
1172
|
+
include: [...makeIdFiltersToMatchWithQuery(toArray(include)), vueQueryFilter],
|
|
1173
|
+
exclude: exclude ? makeIdFiltersToMatchWithQuery(toArray(exclude)) : void 0
|
|
1174
|
+
};
|
|
1123
1175
|
let options = {
|
|
1124
1176
|
isProduction: process.env.NODE_ENV === "production",
|
|
1125
1177
|
compiler: null,
|
|
@@ -1142,6 +1194,16 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1142
1194
|
}
|
|
1143
1195
|
return handleHotUpdate(ctx, options);
|
|
1144
1196
|
},
|
|
1197
|
+
config(config) {
|
|
1198
|
+
return {
|
|
1199
|
+
resolve: {
|
|
1200
|
+
alias: mergeAlias(
|
|
1201
|
+
[{ find: "vue", replacement: "vue/dist/vue.runtime.esm.js" }],
|
|
1202
|
+
config.resolve?.alias
|
|
1203
|
+
)
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
},
|
|
1145
1207
|
configResolved(config) {
|
|
1146
1208
|
options = {
|
|
1147
1209
|
...options,
|
|
@@ -1151,12 +1213,6 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1151
1213
|
cssDevSourcemap: config.css?.devSourcemap ?? false,
|
|
1152
1214
|
devToolsEnabled: !config.isProduction
|
|
1153
1215
|
};
|
|
1154
|
-
if (!config.resolve.alias.some(({ find }) => find === "vue")) {
|
|
1155
|
-
config.resolve.alias.push({
|
|
1156
|
-
find: "vue",
|
|
1157
|
-
replacement: "vue/dist/vue.runtime.esm.js"
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
1216
|
},
|
|
1161
1217
|
configureServer(server) {
|
|
1162
1218
|
options.devServer = server;
|
|
@@ -1164,81 +1220,90 @@ function vuePlugin(rawOptions = {}) {
|
|
|
1164
1220
|
buildStart() {
|
|
1165
1221
|
options.compiler = options.compiler || resolveCompiler(options.root);
|
|
1166
1222
|
},
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1223
|
+
resolveId: {
|
|
1224
|
+
filter: { id: idFilter },
|
|
1225
|
+
async handler(id) {
|
|
1226
|
+
if (id === NORMALIZER_ID || id === HMR_RUNTIME_ID) {
|
|
1227
|
+
return id;
|
|
1228
|
+
}
|
|
1229
|
+
if (parseVueRequest(id).query.vue) {
|
|
1230
|
+
return id;
|
|
1231
|
+
}
|
|
1173
1232
|
}
|
|
1174
1233
|
},
|
|
1175
|
-
load
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
return hmrRuntimeCode;
|
|
1182
|
-
}
|
|
1183
|
-
const { filename, query } = parseVueRequest(id);
|
|
1184
|
-
if (query.vue) {
|
|
1185
|
-
if (query.src) {
|
|
1186
|
-
return fs.readFileSync(filename, "utf-8");
|
|
1234
|
+
load: {
|
|
1235
|
+
filter: { id: idFilter },
|
|
1236
|
+
handler(id, opt) {
|
|
1237
|
+
const ssr = opt?.ssr === true;
|
|
1238
|
+
if (id === NORMALIZER_ID) {
|
|
1239
|
+
return normalizerCode;
|
|
1187
1240
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
if (query.type === "script") {
|
|
1191
|
-
block = getResolvedScript(descriptor, ssr);
|
|
1192
|
-
} else if (query.type === "template") {
|
|
1193
|
-
block = descriptor.template;
|
|
1194
|
-
} else if (query.type === "style") {
|
|
1195
|
-
block = descriptor.styles[query.index];
|
|
1196
|
-
} else if (query.index != null) {
|
|
1197
|
-
block = descriptor.customBlocks[query.index];
|
|
1241
|
+
if (id === HMR_RUNTIME_ID) {
|
|
1242
|
+
return hmrRuntimeCode;
|
|
1198
1243
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1244
|
+
const { filename, query } = parseVueRequest(id);
|
|
1245
|
+
if (query.vue) {
|
|
1246
|
+
if (query.src) {
|
|
1247
|
+
return fs.readFileSync(filename, "utf-8");
|
|
1248
|
+
}
|
|
1249
|
+
const descriptor = getDescriptor(filename, options);
|
|
1250
|
+
let block;
|
|
1251
|
+
if (query.type === "script") {
|
|
1252
|
+
block = getResolvedScript(descriptor, ssr);
|
|
1253
|
+
} else if (query.type === "template") {
|
|
1254
|
+
block = descriptor.template;
|
|
1255
|
+
} else if (query.type === "style") {
|
|
1256
|
+
block = descriptor.styles[query.index];
|
|
1257
|
+
} else if (query.index != null) {
|
|
1258
|
+
block = descriptor.customBlocks[query.index];
|
|
1259
|
+
}
|
|
1260
|
+
if (block) {
|
|
1261
|
+
return {
|
|
1262
|
+
code: block.content,
|
|
1263
|
+
map: block.map
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1204
1266
|
}
|
|
1205
1267
|
}
|
|
1206
1268
|
},
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1269
|
+
transform: {
|
|
1270
|
+
filter: { id: transformIdFilter },
|
|
1271
|
+
async handler(code, id, opt) {
|
|
1272
|
+
const ssr = opt?.ssr === true;
|
|
1273
|
+
const { filename, query } = parseVueRequest(id);
|
|
1274
|
+
if (query.raw) {
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
if (!filter(filename) && !query.vue) {
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
if (!query.vue) {
|
|
1281
|
+
return transformMain(code, filename, options, this, ssr);
|
|
1282
|
+
} else {
|
|
1283
|
+
const descriptor = query.src ? getSrcDescriptor(filename, query) : getDescriptor(filename, options);
|
|
1284
|
+
if (query.type === "template") {
|
|
1285
|
+
return {
|
|
1286
|
+
code: await transformTemplateAsModule(
|
|
1287
|
+
code,
|
|
1288
|
+
descriptor,
|
|
1289
|
+
options,
|
|
1290
|
+
this,
|
|
1291
|
+
ssr
|
|
1292
|
+
),
|
|
1293
|
+
map: {
|
|
1294
|
+
mappings: ""
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
} else if (query.type === "style") {
|
|
1298
|
+
return transformStyle(
|
|
1223
1299
|
code,
|
|
1224
1300
|
descriptor,
|
|
1301
|
+
Number(query.index),
|
|
1225
1302
|
options,
|
|
1226
1303
|
this,
|
|
1227
|
-
|
|
1228
|
-
)
|
|
1229
|
-
|
|
1230
|
-
mappings: ""
|
|
1231
|
-
}
|
|
1232
|
-
};
|
|
1233
|
-
} else if (query.type === "style") {
|
|
1234
|
-
return transformStyle(
|
|
1235
|
-
code,
|
|
1236
|
-
descriptor,
|
|
1237
|
-
Number(query.index),
|
|
1238
|
-
options,
|
|
1239
|
-
this,
|
|
1240
|
-
filename
|
|
1241
|
-
);
|
|
1304
|
+
filename
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1242
1307
|
}
|
|
1243
1308
|
}
|
|
1244
1309
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pedrolamas/plugin-vue2",
|
|
3
|
-
"version": "2.4.0",
|
|
3
|
+
"version": "2.4.2-beta.0",
|
|
4
|
+
"description": "Vite 8 plugin for Vue 2.7 single-file components support",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"author": "Pedro Lamas",
|
|
6
7
|
"files": [
|
|
@@ -33,26 +34,27 @@
|
|
|
33
34
|
"vue": "^2.7.0-0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
37
|
+
"@rolldown/pluginutils": "^1.0.1",
|
|
36
38
|
"@types/fs-extra": "^11.0.4",
|
|
37
39
|
"conventional-changelog-cli": "^2.2.2",
|
|
38
40
|
"debug": "^4.4.3",
|
|
39
41
|
"enquirer": "^2.4.1",
|
|
40
42
|
"esno": "^4.8.0",
|
|
41
43
|
"execa": "^9.6.1",
|
|
42
|
-
"fs-extra": "^11.
|
|
44
|
+
"fs-extra": "^11.4.0",
|
|
43
45
|
"hash-sum": "^2.0.0",
|
|
44
46
|
"minimist": "^1.2.8",
|
|
45
47
|
"picocolors": "^1.1.1",
|
|
46
48
|
"prettier": "^2.8.8",
|
|
47
49
|
"puppeteer": "^24.39.1",
|
|
48
|
-
"rollup": "^4.
|
|
49
|
-
"semver": "^7.
|
|
50
|
+
"rollup": "^4.62.4",
|
|
51
|
+
"semver": "^7.8.5",
|
|
50
52
|
"slash": "^5.1.0",
|
|
51
53
|
"source-map": "^0.7.6",
|
|
52
54
|
"typescript": "^5.9.3",
|
|
53
55
|
"unbuild": "^3.6.1",
|
|
54
|
-
"vite": "^8.
|
|
55
|
-
"vitest": "^4.1.
|
|
56
|
+
"vite": "^8.2.1",
|
|
57
|
+
"vitest": "^4.1.10",
|
|
56
58
|
"vue": "^2.7.16"
|
|
57
59
|
},
|
|
58
60
|
"scripts": {
|