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

2020-05-15 17:46:58 +08:00
 xinfeng1

在自己开发过程中,经常会对着 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/pic_instructions@3x.png" 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 {
       }
     }
   }
 }
}

1265 次点击
所在节点    Vue.js
2 条回复
sunwang
2020-05-20 11:44:40 +08:00
老哥写的不错,像我这种小白可以从中学到一点原理,感谢
xinfeng1
2020-05-20 14:20:30 +08:00
多谢关注🙏,还以为沉了呢。qaq

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/672129

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX