๐Ÿš€Stylify CSS๋กœ Vue.js ์›น์‚ฌ์ดํŠธ๋ฅผ ๋” ๋น ๋ฅด๊ฒŒ ์Šคํƒ€์ผ๋งํ•˜์„ธ์š”

11137 ๋‹จ์–ด vuecsswebdevjavascript
Stylify + ๋ทฐ + ๋น„ํ…Œ. Stylify๋กœ Vue ์›น์‚ฌ์ดํŠธ์˜ ์Šคํƒ€์ผ์„ ๋น ๋ฅด๊ฒŒ ์ง€์ •ํ•˜์„ธ์š”. ์„ ํƒ์ž, ๊ตฌ๋ฌธ ๋ฐ ๋ฌธ์„œ๋ฅผ ์—ฐ๊ตฌํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ์ˆœ์ˆ˜ํ•œ CSS ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๊ณ  ์ƒ์‚ฐ์„ ์œ„ํ•œ ๊ณ ๊ธ‰ ์ตœ์ ํ™”๋กœ ์ƒ์„ฑ๋œ CSS๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

๋” ์‰ฌ์šด ์‹œ์ž‘์„ ์œ„ํ•ด Stylify Stackblitz playground ๐ŸŽฎ์„ ํ™•์ธํ•˜์„ธ์š”.

๐Ÿ’Ž Stylify ์†Œ๊ฐœ



Stylify์€ ์ž‘์„ฑํ•˜๋Š” ๋‚ด์šฉ์— ๋”ฐ๋ผ ๋™์ ์œผ๋กœ CSS๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ตฌ๋ฌธ์€ cssproperty:value ์™€ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ •์˜๋œ ์œ ํ‹ธ๋ฆฌํ‹ฐ๋Š” ๊ตฌ์„ฑ ์š”์†Œ ์„ ํƒ๊ธฐ์™€ ๊ฒฐํ•ฉ๋˜๋ฉฐ ํ”„๋กœ๋•์…˜์—์„œ๋Š” .color\:red,.button {color:red} ~ ._zx,._ga{color:red} ์™€ ๊ฐ™์ด ์ตœ์†Œํ•œ์œผ๋กœ ์ถ•์†Œ๋ฉ๋‹ˆ๋‹ค.

Stylify๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋งค์šฐ ์ž‘์€ ๋ฒˆ๋“ค์„ ๊ฐ€์ ธ์˜ค๊ณ , ์ง€์—ฐ ๋กœ๋“œ๋œ CSS ์ฒญํฌ๋ฅผ ์ถ”๊ฐ€๋กœ ์ƒ์„ฑํ•˜๊ณ , HTML ๋ฐ ์„ ํƒ๊ธฐ ๐ŸคŸ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ํŽ˜์ด์ง€ ์Šคํƒ€์ผ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿš€ Vue.js ์„ค์ •



Vue๋ฅผ ์„ค์ •ํ•˜๋Š” ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์€ cli๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
  • ๋‹ฌ๋ฆฌ๋‹ค yarn create vite app
  • ์„ ํƒ vue
  • ๊ทธ๋Ÿผ cd app

  • ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ธฐ๋ณธ Vue ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์Šค์ผˆ๋ ˆํ†ค์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๐Ÿ”Œ Stylify ํ†ตํ•ฉ



    NPM ๋˜๋Š” Yarn์„ ์‚ฌ์šฉํ•˜์—ฌ @stylify/unplugin ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

    yarn add @stylify/unplugin
    npm i @stylify/unplugin
    

    vite.config.js๋ฅผ ์—ด๊ณ  ๋‹ค์Œ ์ฝ˜ํ…์ธ ๋ฅผ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

    import { defineConfig } from 'vite';
    import vue from '@vitejs/plugin-vue';
    import { vitePlugin } from '@stylify/unplugin';
    
    const stylifyPlugin = vitePlugin({
      transformIncludeFilter: (id) => id.endsWith('vue'),
      bundles: [
        {
          files: ['./src/**/*.vue'],
          outputFile: './src/assets/stylify.css',
        },
      ],
      extend: {
        bundler: {
          compiler: {
            // Match v-bind:class and :class attributes
            selectorsAreas: ['(?:^|\\s+)(?:v-bind)?:class="([^"]+)"'],
          },
        },
      },
    });
    
    export default defineConfig(() => ({
        plugins: [stylifyPlugin, vue()]
    }));
    
    


    ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์—์„œ src/main.js๋ฅผ ์—ด๊ณ  ๊ฒฝ๋กœ๋ฅผ stylify.css์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    // ...
    import './stylify.css'
    


    ์›น์‚ฌ์ดํŠธ ์Šคํƒ€์ผ๋ง



    ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ src/App.vue์— ๋ณต์‚ฌํ•˜๊ณ  yarn dev๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์Šคํƒ€์ผ์ด ์ง€์ •๋œ Hello World! ๐ŸŽ‰ ํ…์ŠคํŠธ๋ฅผ ์–ป๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

    <template>
      <div class="max-width:800px margin:0__auto">
        <h1 class="text-align:center margin-top:100px font-size:42px">Hello World!๐Ÿคฉ</h1>
      </div>
    </template>
    


    Stylify๋Š” ๋ฒˆ๋“ค ํŒŒ์ผ์˜ ๋งˆ์Šคํฌ์™€ ์ผ์น˜ํ•˜๋Š” ํŒŒ์ผ์˜ ๋ชจ๋“  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๊ฐ์‹œํ•˜๊ณ  CSS๋ฅผ src/stylify.css ์— ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด color:blue ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด CSS๊ฐ€ ์ž๋™์œผ๋กœ ์—…๋ฐ์ดํŠธ๋ฉ๋‹ˆ๋‹ค ๐ŸŽ‰.

    Stackblitz.com ๐Ÿ’ก์—์„œ ์ง์ ‘ Stylify๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด์‹ญ์‹œ์˜ค.

    ๊ตฌ์„ฑํ’ˆ



    ์œ ํ‹ธ๋ฆฌํ‹ฐ๋กœ ์ธํ•ด ํ…œํ”Œ๋ฆฟ์ด ๋„ˆ๋ฌด ์ปค์ง€๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    content options (๋Œ€๊ด„ํ˜ธ ์—†๋Š” javascript ๊ฐœ์ฒด ์˜ˆ์ƒ) ๋˜๋Š” compiler config ์„ ํ†ตํ•ด ์‚ฌ์šฉ๋˜๋Š” ํŒŒ์ผ์—์„œ ์ง์ ‘ ๊ตฌ์„ฑ ์š”์†Œ.

    <!--
    stylify-components
      container: 'max-width:800px margin:0__auto',
      title: 'text-align:center margin-top:100px font-size:42px'
    /stylify-components
    -->
    <template>
      <div class="container">
        <h1 class="title">Hello World!๐Ÿคฉ</h1>
      </div>
    </template>
    


    ๋ณ€์ˆ˜



    ๊น”๋”ํ•œ ์ฝ”๋“œ๊ฐ€ ๋งˆ์Œ์— ๋“ ๋‹ค๋ฉด ์„ ํƒ๊ธฐ์—์„œ ํ•˜๋“œ์ฝ”๋”ฉ๋œ ๊ฐ’๋„ ํ”ผํ•˜๊ณ  ์‹ถ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. Variables์€ ๊ตฌ์„ฑ ์š”์†Œ์™€ ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    <!--
    stylify-variables
      titleFontSize: '42px',
      containerWidth: '800px'
    /stylify-variables
    
    stylify-components
      container: 'max-width:$containerWidth margin:0__auto',
      title: 'text-align:center margin-top:100px font-size:$titleFontSize'
    /stylify-components
    -->
    <template>
      <div class="container">
        <h1 class="title">Hello World!๐Ÿคฉ</h1>
      </div>
    </template>
    


    ์ƒ์‚ฐ์„ ์œ„ํ•œ ๊ฑด๋ฌผ


    yarn build + yarn preview ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด vue ๋งˆํฌ์—…์ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์—‰๋ง์ด ๋ฉ๋‹ˆ๋‹ค.

    <template>
      <div class="_7tcrv">
        <h1 class="_88io">Hello World!๐Ÿคฉ</h1>
      </div>
    </template>
    


    CSS๋„ ๋‹จ์ถ•๋ฉ๋‹ˆ๋‹ค.

    :root {--titleFontSize: 42px;--containerWidth: 800px;}
    ._bcda8,._7tcrv{max-width:800px}
    ._m0vnad,._7tcrv{margin:0 auto}
    ._1vegb8,._88io{text-align:center}
    ._jimir,._88io{margin-top:100px}
    ._qe393,._88io{font-size:42px}
    


    ํ•„์š”ํ•œ ๋ชจ๋“  ๊ตฌ์„ฑ



    ์œ„์˜ ์˜ˆ์—๋Š” Stylify๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๊ฒƒ์ด ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ํ…œํ”Œ๋ฆฟ
  • ์—์„œ nested files์„ ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์Šคํƒ€์ผ global selectors
  • ์ •์˜ํ•˜๋‹ค custom screens
  • ์—ฌ๋ฐฑ ์™ผ์ชฝ
  • ์— ๋Œ€ํ•ด ml:20px์™€ ๊ฐ™์€ own macros ์ถ”๊ฐ€
  • ๊ธฐํƒ€

  • ์ž์„ธํ•œ ๋‚ด์šฉ์€ checkout the docs๋กœ ๋ฌธ์˜ํ•˜์‹ญ์‹œ์˜ค ๐Ÿ’Ž.


    ์—ฐ๋ฝ์„ ์œ ์ง€ํ•˜๋‹ค:

    ๐Ÿ‘‰
    ๐Ÿ‘‰
    ๐Ÿ‘‰ stylifycss.com
    ๐Ÿ‘‰
    ๐Ÿ‘‰ medium.com/@8machy

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ