How to configure VueJS + PostCss + Tailwind with Storybook

后端 未结 3 1102
自闭症患者
自闭症患者 2021-02-08 00:38

Anyone have success setting up a project using VueJS, PostCss, and Tailwind with component development in Storybook?

I\'ve gotten this far:

  1. New vue
3条回答
  •  Happy的楠姐
    2021-02-08 01:13

    I've got a fully working example of Svelte + TailwindCSS + Storybook in this github repo https://github.com/jerriclynsjohn/svelte-storybook-tailwind

    But Integrating should be very much similar:

    1. Once TailwindCSS is integrated with your Vue project, then follow on.
    2. Add a custom webpack.config.js in your .storybook folder and add the following:
    const path = require('path');
    
    module.exports = ({ config, mode }) => {
    
      config.module.rules.push({
        test: /\.css$/,
        loaders: [
          {
            loader: 'postcss-loader',
            options: {
              sourceMap: true,
              config: {
                path: './.storybook/',
              },
            },
          },
        ],
    
        include: path.resolve(__dirname, '../storybook/'),
      });
    
      return config;
    };
    
    1. Create a postcss.config.js in your .storybook folder with the following:
    var tailwindcss = require('tailwindcss');
    
    module.exports = {
      plugins: [
        require('postcss-import')(),
        tailwindcss('./tailwind.config.js'), //This refers to your tailwind config
        require('autoprefixer'),
      ],
    };
    
    1. Add a utils.css file in your storybook folder
    @import 'tailwindcss/base';
    
    @import 'tailwindcss/components';
    
    @import 'tailwindcss/utilities';
    
    1. Reference your CSS file in the <>.stories.js:
    import '../../css/utils.css';
    

    I really recommend you refer to the implementation in the github repo, it also has things that are specific to Storybook. (Github)

提交回复
热议问题