0.0.1 • Published 10 months ago

babel-plugin-import-to-string v0.0.1

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

babel-plugin-import-to-string

将 import 语句中的路径提取出来。


Example

转换前

import otherRouter from "./otherRouter";
import Cmp from "./Cmp";

/* -------------------------- 首页 -------------------------- */
const index = () => import("../pages/home/index.vue");
const home = () => import("../pages/home/home.vue");

const routes = [
  {
    path: "*",
    redirect: "/home",
    menu: false,
    component: Cmp,
  },
  {
    path: "/index",
    name: "index",
    component: index,
    text: "首页",
    menu: true,
  },
  ...otherRouter
];


export default routes;

配置文件

  • babelrc
{
  "plugins": [
    [
      "babel-plugin-import-to-string",
      {
        "ignoreImport": ["./otherRouter", "../pages/home/home.vue"]
      }
    ]
  ],
  "presets": []
}

转换后

import otherRouter from "./otherRouter";
const Cmp = "./Cmp";
/* -------------------------- 首页 -------------------------- */
const index = "../pages/home/index.vue";
const home = () => import("../pages/home/home.vue");
const routes = [{
  path: "*",
  redirect: "/home",
  menu: false,
  component: Cmp
}, {
  path: "/index",
  name: "index",
  component: index,
  text: "首页",
  menu: true
}, ...otherRouter];
export default routes;
0.0.1

10 months ago