GithubHelp home page GithubHelp logo

andybee / arc-plugin-tailwindcss Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 678 KB

TailwindCSS workflow integration for Architect

Home Page: https://www.npmjs.com/package/arc-plugin-tailwindcss

JavaScript 92.06% CSS 0.56% Arc 2.20% HTML 5.18%
tailwindcss aws-lambda architect

arc-plugin-tailwindcss's Introduction

TailwindCSS workflow integration for Architect

Install

Into your existing Architect project:

npm i arc-plugin-tailwindcss --save-dev

Add the following to your Architect project manifest (usually app.arc):

@plugins
arc-plugin-tailwindcss

Usage

Now, simply author HTTP Lambdas in the src tree and HTML or client-side JavaScript in public with TailwindCSS utility classes:

// src/http/get-index/index.js
exports.handler = async () => ({
  statusCode: 200,
  headers: {
    'content-type': 'text/html; charset=utf8'
  },
  body: `
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link href="/style.css" rel="stylesheet">
    </head>
    <body>
      <h1 class="text-3xl font-bold underline">
        Hello world!
      </h1>
    </body>
    </html>
  `,
})

The above function will trigger TailwindCSS to generate a CSS file includes the text-3xl, font-bold and underline utility classes.

When working locally, Sandbox runs the TailwindCSS CLI which automatically detects changes to your functions and public HTML and client-side JavaScript and updates the CSS file for you.

Configuration

tailwind.config.js

This plugin will create a new tailwind.config.js for you if one does not already exist at the root of the project.

Project manifest settings

The following higher-level settings are also available in your Architect project manifest:

  • src - configure the source CSS file location; defaults to src/styles/tailwind.css
    • If the file does not exist on Sandbox startup, a default CSS file will be created
  • build - configure the build file location; defaults to public/style.css
    • Note: make sure you add this directory to your .gitignore
  • minify - enable minification of your CSS file on deployment; defaults to true

Example:

@tailwindcss
# Read base CSS file `./src/my-styles.css`
src src/my-styles.css

# Output CSS file to `./public/foo/styles.css`
build public/foo/style.css

# Minify the CSS file prior to deployment
minify true

arc-plugin-tailwindcss's People

Contributors

andybee avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

arc-plugin-tailwindcss's Issues

Move `tailwindcss` to `peerDependencies`?

I'm considering moving tailwindcss to a peer dependency, pinned to the current major release version.

As v3 minor releases of Tailwind shouldn't impact anything this plugin does, this allows a bit more freedom for those using the plugin to upgrade/downgrade Tailwind as they see fit independent of the plugin itself.

On a purely selfish basis, this also avoids me having to increment the plugin when a new minor release comes out, I would just need to road test major versions if/when they are released.

Unless anyone can think of a compelling reason to not do this, I'll look to implement this in the next few weeks.

Failing to start in local sandbox

This plugin is failing to start after the initial setup.

Error

...
    http://localhost:3333

√ Sandbox Started in 180ms
√ Local environment ready!

○ Sandbox Running 1 Sandbox startup plugin
node:events:498
      throw er; // Unhandled 'error' event
      ^

Error: spawn npx ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn npx',
  path: 'npx',
  spawnargs: [
    'tailwindcss',
    '-c',
    'C:\\code\\github\\jonmaestas\\project1\\tailwind.config.js',
    '-i',
    'C:\\code\\github\\jonmaestas\\project1\\src\\styles\\tailwind.css',
    '-o',
    'C:\\code\\github\\jonmaestas\\project1\\public\\style.css',
    '-w'
  ]
}

Manually running npx tailwindcss works:

npx tailwind -c ./tailwind.config.js -i ./src/styles/tailwind.css -o ./public/style.css -w

Rebuilding...

Done in 432ms.

It appears to be something with the path expansion.

Steps to reproduce

  1. Run npm i arc-plugin-tailwindcss --save-dev

  2. Add plugin to /app.arc

@plugins
arc-plugin-tailwindcss
  1. Run npm start

I haven't pushed this to staging yet since it's not working locally.

Machine

I am running Windows 10. It fails with both Gitbash and Powershell.

package.json

{
  "name": "project1",
  "version": "0.1.0",
  "author": "Jon Maestas",
  "repository": {
    "type": "git",
    "url": "https://github.com/jonmaestas/project1.git"
  },
  "dependencies": {
    "aws-sdk": "^2.1237.0",
    "bcrypt": "^5.0.1"
  },
  "scripts": {
    "start": "npx arc sandbox",
  },
  "devDependencies": {
    "@architect/architect": "^10.7.1",
    "@architect/functions": "^5.2.3",
    "@architect/plugin-budget-watch": "^0.0.4",
    "arc-plugin-tailwindcss": "^0.1.1"
  }
}

Allow TailwindCSS config file to be user configurable

Allow the user to change the path/filename of the Tailwind config.

When updating the documentation for this change, it might be worth adding to the existing text the created config files include some useful defaults, specific to an Architect project.

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.