代码改变世界

js 前端使用 prettier格式化scss

  muamaker  阅读(904)  评论(0编辑  收藏  举报

一、使用 prettier 插件,在纯前端 格式一些代码

参加 https://prettier.io/docs/en/browser.html

 

二、这里以 scss 为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
         
            <script type="text/javascript" src="https://unpkg.com/prettier@2.6.1/standalone.js"></script>
            <script type="text/javascript"  src="https://unpkg.com/prettier@2.6.1/parser-postcss.js"></script>
 
    </head>
    <body>
    </body>
    <script type="text/javascript">
            let result = prettier.format(`.frame {
            height: 100%;
            position: relative;
            background-color: #ffffff;
            iframe {
                width: 100%;
                height: 100%;
            }
            &:before {
                content: 'Preview';
                position: absolute;
                left: 50%;
                top: 50%;
                font-size: 3vw;
                transform: translate(-50%, -50%);
                opacity: 0.15;
                color: #999;
            }
            &.fullScreen {
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                z-index: 100;
            }
            &:hover {
                .el-icon-full-screen {
                    display: block;
                }
            }
        }`,{parser:"scss", 'plugins': window.prettierPlugins});
         
        console.log(result);
    </script>
</html>

  

相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示