使用 Plop 修改现有文件?

互联网 行业动态 更新时间:2024-06-13 00:21:05

Bra*_*ham 10

这就是我最终把它拉下来的方式:

在我的index.js文件(我要修改的那个)中,我在应该插入的地方添加了两条注释:

…
import { PointAountCard } from './ponents/PointAountCard';
import { Card } from './ponents/Card';
import { SettingsPanelFooter } from './ponents/SettingsPanelFooter';
// COMPONENT IMPORTS

export {
    …
    PointAountCard,
    Card,
    SettingsPanelFooter,
// COMPONENT EXPORTS
};

然后在我的plopfile.js配置中,我将这两个步骤添加到我的actions配置中:

module.exports = function (plop) {
    plop.setGenerator('ponent', {
        actions: [
            …
            {
                path: '../../src/index.js',
                pattern: /(\/\/ COMPONENT IMPORTS)/g,
                template: 'import { {{name}} } from \'./ponents/{{name}}\';\n$1',
                type: 'modify',
            },
            {
                path: '../../src/index.js',
                pattern: /(\/\/ COMPONENT EXPORTS)/g,
                template: '\t{{name}},\n$1',
                type: 'modify',
            },
        ],
        description: 'New React Component',
        prompts: [
            …
        ],
    })
};

所有新组件都会自动添加到index.js文件中。

更多推荐

文件,Plop

本文发布于:2023-04-23 10:34:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/08dc7d6d9c1b8284fce2f46986d2ac98.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Plop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!