1.0.0 • Published 6 years ago

babel-plugin-ynw v1.0.0

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

babel-plugin-ynw

使用

1.安装

npm i --save-dev babel-plugin-ynw

2.配置

// .babelrc文件
{
  plugins: ["ynw"];
}

ynRegisteVueComps

自动注册 Vue 组件

// 自动注册 comps 文件夹下面的 .vue 文件为  VUE 组件 (带有 yn 前缀)
// 出于性能的考虑, 没有设置自定义参数, 也就是说需要把组件放在 "comps" 文件夹
ynRegisteVueComps();

// 以上一行代码会转义为这一坨代码
const compContext = require.context("./comps", true, /\.vue$/);
compContext.keys().forEach(p => {
  const getCompPathName = path => {
    const match = path.match(/\w+?(?=\/)/g);
    if (!match) return "";
    return match.map(item => item.replace(/\//g, "")).join("-") + "-";
  };
  const name = p.match(/([\w\-]+)\.vue$/)[1];
  const folder = getCompPathName(p);
  const option = compContext(p).default;
  Vue.component("yn-" + folder + name, option);
});
1.0.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.4

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago