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