V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xinfeng1
V2EX  ›  Vue.js

npm 插件,抽离*.vue 中的模版代码生成 Scss 代码骨架

  •  
  •   xinfeng1 · 2020-05-15 17:46:58 +08:00 · 1250 次点击
    这是一个创建于 1443 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在自己开发过程中,经常会对着 UI 切图,一次性将 HTML 骨架给写完,然后在 sass/less 文件中,照着 HTML 代码写一遍 CSS 层级,最后填充样式。

    觉得这样麻烦,然后手撕了个 npm 插件,直接将 template 转为 sass 骨架代码

    github 地址: https://github.com/wuyic/t2css


    使用方法

    npm i -D t2css

    npx t2css sourceFilePath targetSourceFile

    生成前的 Vue 代码

    ./a.vue 文件
    <template>
      <div class="testArea">
        <div class="instruction i1">
          <img class="img" src="@/images/common/[email protected]" alt="">
        </div>
        <div class="instruction1 i2">
          <p class="p">ssds</p>
          <img src="" alt="">
        </div>
        <div>
          <div class="is3">
            <div class="is33">
              <div>
                <div class="is333">
                    <img src="" alt="">
                    <img src="" alt="">
                    <img src="" alt="">
                    <img src="" alt="">
                    <img src="" alt="">
                    <img src="" alt="">
                    <img src="" alt="">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </template>
    

    生成后的 SCSS 骨架:

    .testArea {
     .instruction {
       &.i1 {
       }
       .img {
       }
     }
     .instruction1 {
       &.i2 {
       }
       .p {
       }
       img {
       }
     }
     .is3 {
       .is33 {
         .is333 {
           img {
           }
         }
       }
     }
    }
    
    
    2 条回复    2020-05-20 14:20:30 +08:00
    sunwang
        1
    sunwang  
       2020-05-20 11:44:40 +08:00
    老哥写的不错,像我这种小白可以从中学到一点原理,感谢
    xinfeng1
        2
    xinfeng1  
    OP
       2020-05-20 14:20:30 +08:00
    多谢关注🙏,还以为沉了呢。qaq
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   982 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:21 · PVG 03:21 · LAX 12:21 · JFK 15:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.