xinfeng1
V2EX  ›  Vue.js

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

  •  
  •   xinfeng1 · May 15, 2020 · 2096 views
    This topic created in 2264 days ago, the information mentioned may be changed or developed.

    在自己开发过程中,经常会对着 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 replies    2020-05-20 14:20:30 +08:00
    sunwang
        1
    sunwang  
       May 20, 2020
    老哥写的不错,像我这种小白可以从中学到一点原理,感谢
    xinfeng1
        2
    xinfeng1  
    OP
       May 20, 2020
    多谢关注🙏,还以为沉了呢。qaq
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1004 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:10 · PVG 06:10 · LAX 15:10 · JFK 18:10
    ♥ Do have faith in what you're doing.