1.0.0 • Published 4 years ago
acc-vue-cli-plugin-acode v1.0.0
acc-auto-code-webpack-plugin
需要环境配置
- webpack >= 2
 - nodejs >= 8
 
参数配置
- useFileboolean default false description 是否监听文件(默认只监听文件夹)
 - maxlevelstring default 1 description 文件监听层级
 - inPathstring default 没有默认必传参数 description 监听的文件路径
 - outPathstring default inPath + '/index.js' description 自动生成的文件
 - templateEachfunction default 没有默认必传参数 paranm fileName文件名称 paranm filePath文件路径 description 需要遍历生成的模板
 - outfunction default template => template paranm template遍历生成的文本 paranm modules模块 description 最终生成的文本
 
例子
// 自动化编码补丁
new AutoCodePlugin([{
    // 使用文件模式
    useFile: true,
    /*********** 组件自动化注册 ***********/
    // 文件监听等级
    maxlevel: 1,
    // 监听./src/router/*下的文件夹
    inPath: './src/components',
    // 自动在./src/router/目录下生成index.js
    outPath: './src/components/index.js',
    // 模板
    // fileName: 文件夹名称
    // filePath: 文件夹路径
    templateEach: (fileName, filePath) => {
        return `Vue.component('${fileName}', () => import('${filePath}'));`;
    },
    /** 
        * 输出模板
        * template: 模板名称
        * modules: 模板模块名称
    */
    out: (template, modules) => {
        return `
            /**
                * acc-team
                * Date ${new Date()}
                * 组件自动化注册
                */
            import Vue from 'vue/dist/vue.esm.js';
            ${template}
        `;
    }
    /*********** 组件自动化注册 ***********/
}, {
    /*********** 路由自动化注册 ***********/
    // 文件监听等级
    maxlevel: 1,
    // 监听./src/router/*下的文件夹
    inPath: './src/pages',
    // 自动在./src/router/目录下生成index.js
    outPath: './src/pages/index.js',
    // 模板
    // fileName: 文件夹名称
    // filePath: 文件夹路径
    templateEach: (fileName, filePath) => {
        return `{ path: '/${fileName}', component: () => import('${filePath}') },`;
    },
    /** 
        * 输出模板
        * template: 模板名称
        * modules: 模板模块名称
    */
    out: (template, modules) => {
        return `
            /**
                * acc-team
                * Date ${new Date()}
                *  路由自动化注册
                */
            import VueRouter from 'vue-router';
            // 路由配置
            const routes = [
                { path: '/', redirect: '/page1' },
                ${template}
            ];
            // 实例化路由
            const router = new VueRouter({
                routes
            });
            export default router;
        `;
    }
    /*********** 路由自动化注册 ***********/
}])启动测试环境
yarn run serve打包测试环境
yarn run build测试环境安装
yarn install启动测试环境
yarn run serve打包测试环境
yarn run buildCustomize configuration
1.0.0
4 years ago