Skip to content

zFitness/babel-plugin-import-to-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-import-to-string

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

NPM version


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;

About

import path -> string

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published