UNPKG

1.15 kBJavaScriptView Raw
1import { declare } from "@babel/helper-plugin-utils";
2import * as fs from "fs";
3import {parse as parseXml} from "fast-xml-parser";
4
5import pluginTransformTypeScript from "@babel/plugin-transform-typescript";
6import presetTypeScript from "@babel/preset-typescript";
7
8
9export default declare(
10 (api, { jsxPragma, allExtensions = false, isTSX = false }) => {
11
12 api.assertVersion(7);
13
14 return {
15 "presets": [
16 [presetTypeScript, { jsxPragma, allExtensions, isTSX }]
17 ],
18 "overrides": [{
19 "test": filePath => {
20 if(/\.vue$/.test(filePath)) {
21
22 const json = parseXml(fs.readFileSync(filePath, {encoding: "utf8"}), {
23 ignoreAttributes: false
24 });
25
26 if(json.script && typeof json.script === "object" && typeof json.script["@_lang"] === "string" && json.script["@_lang"].toLowerCase() === "ts") {
27 return true;
28 }
29
30 }
31
32 return false;
33
34 },
35 "plugins": [
36 [pluginTransformTypeScript, {
37 jsxPragma,
38 allExtensions,
39 isTSX
40 }]
41 ]
42 }]
43 };
44 }
45);