Code Monkey home page Code Monkey logo

snowpack-tailwindcss-setup's Introduction

๐Ÿ˜ TailwindCSS 2.x with Snowpack Setup

๐Ÿ˜ž Important Note

The setup was slow when I used the tailwind directives like @apply inside the CSS files


List of packages installed

Package Name Version
@snowpack/plugin-postcss ^1.1.0
@tailwindcss/postcss7-compat ^2.0.2
autoprefixer ^10.2.3
postcss ^8.2.4
postcss-cli ^8.3.1
snowpack ^3.0.11
tailwindcss ^2.0.2

๐Ÿ˜Š Clone this repo

  • Install Packages
  npm install
  • To run the dev server
npm run start
  • To run the prod build
npm run build

๐Ÿค”๐Ÿค” Just in case you want to setup everything from scratch.

Steps to Follow

  • open the folder(your project folder) and run

    npm init -y
    

    to create package.json with default settings.

  • Install Snowpack using

    npm i snowpack -D
    
  • add these scripts to your package.json

    "scripts": {
      "start": "snowpack dev",
      "build": "snowpack build"
    },
    

    start - to run the local development server. build - to create a production build

  • Let's install TailwindCSS 2.x

    npm install tailwindcss@latest postcss@latest autoprefixer@latest -D
    
  • next we need to create tailwind.config.js and postcss.config.js. To generate these files run

    npx tailwindcss init -p
    
  • add tailwindcss and autoprefixer to the postcss plugins inside postcss.config.js

    module.exports = {
      plugins: [require("tailwindcss"), require("autoprefixer")],
    };
    
  • next we need to instruct snowpack to run postcss. Install snowpack postcss plugin

    npm install @snowpack/plugin-postcss postcss postcss-cli -D
    
  • next we need to create snowpack.config.js in the root of the project directory and add the following code

    module.exports = {
        plugins: ["@snowpack/plugin-postcss"],
    };
    

๐Ÿฅณ๐Ÿ˜ Finally we are ready to create html css and js files.

  • create these files inside the root of the project directory
    • index.html
    • index.css
    • index.js

add tailwind css rules inside the index.css

@tailwind base;
@tailwind components;
@tailwind utilities;
  • Add index.css to index.html using

     <link rel="stylesheet" href="index.css" />
    

โœ‹ FOR PRODUCTION BUILD

  • Add purge rule to tailwind.config.js
module.exports = {
  purge: ["./**/*.html"],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
};

and run

npm run build

which creates a build folder.

Made with โค๏ธ - by FrontEndFunn

snowpack-tailwindcss-setup's People

Contributors

frontendfunn avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.