1 | import { declare } from "@babel/helper-plugin-utils";
|
2 | import * as fs from "fs";
|
3 | import {parse as parseXml} from "fast-xml-parser";
|
4 |
|
5 | import pluginTransformTypeScript from "@babel/plugin-transform-typescript";
|
6 | import presetTypeScript from "@babel/preset-typescript";
|
7 |
|
8 |
|
9 | export 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 | );
|