| 
 | 1 | +# Adding TailwindCSS Support  | 
 | 2 | + | 
 | 3 | +Using [TailwindCSS](https://tailwindcss.com/) is optional and needs to be configured, if desired. To style your extension popup or options page using Tailwind, you will need to install the required dependencies and configure the webpack build steps.  | 
 | 4 | + | 
 | 5 | +Below you find the required steps to configure Vue-Web-Extension for TailwindCSS.  | 
 | 6 | + | 
 | 7 | +1. Install dependencies `postcss-loader @fullhuman/postcss-purgecss`:  | 
 | 8 | + | 
 | 9 | +    ``` bash  | 
 | 10 | +    # with npm:  | 
 | 11 | +    npm install postcss-loader @fullhuman/postcss-purgecss tailwindcss --only=dev  | 
 | 12 | + | 
 | 13 | +    # using yarn:  | 
 | 14 | +    yarn add postcss-loader @fullhuman/postcss-purgecss tailwindcss --dev  | 
 | 15 | +    ```  | 
 | 16 | + | 
 | 17 | +2. Update your `webpack.config.js` to use `postcss-loader`:  | 
 | 18 | + | 
 | 19 | +    ``` diff  | 
 | 20 | +        {  | 
 | 21 | +            test: /\.css$/,  | 
 | 22 | +    +        use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],  | 
 | 23 | +    -        use: [MiniCssExtractPlugin.loader, 'css-loader'],  | 
 | 24 | +        },  | 
 | 25 | +    ```  | 
 | 26 | + | 
 | 27 | +3.  Create a file called `postcss.config.js` next to your `webpack.config.js` with the following contents:  | 
 | 28 | + | 
 | 29 | +    ``` js  | 
 | 30 | +    /* eslint-disable import/no-extraneous-dependencies */  | 
 | 31 | +    const tailwindcss = require('tailwindcss');  | 
 | 32 | +
  | 
 | 33 | +    const purgecss = require('@fullhuman/postcss-purgecss')({  | 
 | 34 | +        // Specify the paths to all of the template files in your project  | 
 | 35 | +        content: ['./src/**/*.vue'],  | 
 | 36 | +
  | 
 | 37 | +        // Include any special characters you're using in this regular expression  | 
 | 38 | +        defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],  | 
 | 39 | +
  | 
 | 40 | +        extractors: [  | 
 | 41 | +            // https://purgecss.com/guides/vue.html  | 
 | 42 | +            {  | 
 | 43 | +                extensions: ['vue'],  | 
 | 44 | +                extractor(content) {  | 
 | 45 | +                    const contentWithoutStyleBlocks = content.replace(/<style[^]+?<\/style>/gi, '');  | 
 | 46 | +                    return contentWithoutStyleBlocks.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || [];  | 
 | 47 | +                },  | 
 | 48 | +            },  | 
 | 49 | +        ],  | 
 | 50 | +
  | 
 | 51 | +        whitelist: [],  | 
 | 52 | +        whitelistPatterns: [  | 
 | 53 | +            /-(leave|enter|appear)(|-(to|from|active))$/, // transitions  | 
 | 54 | +            /data-v-.*/, // scoped css  | 
 | 55 | +        ],  | 
 | 56 | +    });  | 
 | 57 | +
  | 
 | 58 | +    module.exports = {  | 
 | 59 | +        plugins: [tailwindcss(), ...(process.env.NODE_ENV === 'production' ? [purgecss] : [])],  | 
 | 60 | +    };  | 
 | 61 | +    ```  | 
 | 62 | +
  | 
 | 63 | +4. Add Tailwind Directives:  | 
 | 64 | +
  | 
 | 65 | +    To make the Tailwind classes available you need to add the following lines to your `src/popup/App.vue`-file:  | 
 | 66 | +
  | 
 | 67 | +    ``` vue  | 
 | 68 | +    <style>  | 
 | 69 | +    @tailwind base;  | 
 | 70 | +    @tailwind components;  | 
 | 71 | +    @tailwind utilities;  | 
 | 72 | +    </style>  | 
 | 73 | +   ```  | 
 | 74 | +
  | 
 | 75 | +   In a similar way you can add it to the options page of course.  | 
 | 76 | +
  | 
 | 77 | +Now you should be able to use the commonly used Tailwind classes in your web-extension.  | 
0 commit comments