@unocss/extractor-pug 0.12.5 → 0.12.9

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
2
+ var regexVueTemplate = /<template.*?lang=['"]pug['"][^>]*?>\n([\s\S]*?\n)<\/template>/gm;
2
3
  function extractorPug() {
3
4
  async function compile(code, id) {
4
5
  const Pug = await Promise.resolve().then(() => require("pug"));
@@ -13,11 +14,23 @@ function extractorPug() {
13
14
  async extract(ctx) {
14
15
  if (!ctx.id)
15
16
  return;
16
- if (ctx.id.endsWith(".pug") || ctx.id.match(/\.vue\?vue&type=template/)) {
17
+ if (ctx.id.match(/\.pug$/) || ctx.id.match(/\?vue&type=template/)) {
17
18
  try {
18
19
  ctx.code = await compile(ctx.code, ctx.id) || ctx.code;
19
20
  } catch (e) {
20
21
  }
22
+ } else if (ctx.id.match(/\.vue$/)) {
23
+ const matches = Array.from(ctx.code.matchAll(regexVueTemplate));
24
+ let tail = "";
25
+ for (const match of matches) {
26
+ if (match && match[1])
27
+ tail += `
28
+ ${await compile(match[1], ctx.id)}`;
29
+ }
30
+ if (tail)
31
+ ctx.code = `${ctx.code}
32
+
33
+ ${tail}`;
21
34
  }
22
35
  return void 0;
23
36
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ var regexVueTemplate = /<template.*?lang=['"]pug['"][^>]*?>\n([\s\S]*?\n)<\/template>/gm;
2
3
  function extractorPug() {
3
4
  async function compile(code, id) {
4
5
  const Pug = await import("pug");
@@ -13,11 +14,23 @@ function extractorPug() {
13
14
  async extract(ctx) {
14
15
  if (!ctx.id)
15
16
  return;
16
- if (ctx.id.endsWith(".pug") || ctx.id.match(/\.vue\?vue&type=template/)) {
17
+ if (ctx.id.match(/\.pug$/) || ctx.id.match(/\?vue&type=template/)) {
17
18
  try {
18
19
  ctx.code = await compile(ctx.code, ctx.id) || ctx.code;
19
20
  } catch (e) {
20
21
  }
22
+ } else if (ctx.id.match(/\.vue$/)) {
23
+ const matches = Array.from(ctx.code.matchAll(regexVueTemplate));
24
+ let tail = "";
25
+ for (const match of matches) {
26
+ if (match && match[1])
27
+ tail += `
28
+ ${await compile(match[1], ctx.id)}`;
29
+ }
30
+ if (tail)
31
+ ctx.code = `${ctx.code}
32
+
33
+ ${tail}`;
21
34
  }
22
35
  return void 0;
23
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/extractor-pug",
3
- "version": "0.12.5",
3
+ "version": "0.12.9",
4
4
  "description": "UnoCSS extractor for Pug",
5
5
  "keywords": [
6
6
  "unocss",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/pug": "^2.0.5",
45
- "@unocss/core": "0.12.5",
45
+ "@unocss/core": "0.12.9",
46
46
  "pug": "^3.0.2"
47
47
  },
48
48
  "scripts": {