tailwindInstallOnVue - PEACH-BROS/lets-merge GitHub Wiki

Vue์— Tailwind ์ ์šฉํ•˜๊ธฐ

์ˆœ์„œ

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

vue ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ (vue-cli ๋ฒ„์ „3 ์ด์ƒ) vue create [project ์ด๋ฆ„]

cd [project ์ด๋ฆ„]

tailwindcss ์„ค์น˜ ๋ฐ ์ ์šฉ

tailwindcss ์„ค์น˜ npm install tailwindcss

/* src/assets/css/tailwind.css */

@tailwind base;

@tailwind components;

@tailwind utilities;
// src/main.js

...
import "@/assets/css/tailwind.css";
...

project root dir ์—์„œ npx tailwindcss init --full
tailwind.config.js ์— ์›ํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ,ํ…Œ๋งˆ ๋“ฑ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ

// /postcss.config.js

const autoprefixer = require('autoprefixer')
const tailwindcss = require('tailwindcss')

module.exports = {
    plugins: [autoprefixer, tailwindcss]
}

ํŒŒ์ผ ์‚ฌ์ด์ฆˆ ์ค„์ด๊ธฐ

npm install @fullhuman/postcss-purgecss --save-dev

// postcss.config.js ๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.
const autoprefixer = require('autoprefixer')
const tailwindcss = require('tailwindcss')

const purgecss = require('@fullhuman/postcss-purgecss')({

    // Specify the paths to all of the template files in your project
    content: [
        './src/**/*.html',
        './src/**/*.vue',
        './src/**/*.jsx',
        // etc.
    ],

    // This is the function used to extract class names from your templates
    defaultExtractor: content => {
        // Capture as liberally as possible, including things like `h-(screen-1.5)`
        const broadMatches = content.match(/[^<>"'`\s]*[^<>"'`\s:]/g) || []

        // Capture classes within other delimiters like .block(class="w-1/2") in Pug
        const innerMatches = content.match(/[^<>"'`\s.()]*[^<>"'`\s.():]/g) || []

        return broadMatches.concat(innerMatches)
    }
})

module.exports = {
    plugins: [
        autoprefixer,
        tailwindcss,
        ...process.env.NODE_ENV === 'production'
            ? [purgecss]
            : []
    ]
}