├── .circleci
└── config.yml
├── .github
└── main.workflow
├── .gitignore
├── LICENSE
├── README.md
├── babel-plugin-macros.config.js
├── cypress.json
├── cypress
├── .eslintrc
├── e2e
│ └── App.spec.js
├── plugins
│ └── index.js
├── snapshots
│ ├── All Specs
│ │ └── The App should be styled -- successfully loads styled.snap.png
│ └── App.spec.js
│ │ └── The App should be styled -- successfully loads styled.snap.png
└── support
│ ├── commands.js
│ └── index.js
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
├── renovate.json
└── src
├── App.css
├── App.js
├── App.test.js
├── index.css
├── index.js
├── logo.svg
├── serviceWorker.js
├── tailwind.config.js
└── tailwind.js
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2 # use CircleCI 2.0
2 | jobs: # a collection of steps
3 | build: # runs not using Workflows must have a `build` job as entry point
4 | docker: # run the steps with Docker
5 | - image: cypress/base:16
6 | environment:
7 | ## this enables colors in the output
8 | TERM: xterm
9 | working_directory: ~/app # directory where steps will run
10 | steps: # a collection of executable commands
11 | - checkout # special step to check out source code to working directory
12 | ##########################
13 | # install base dependencies
14 | - restore_cache: # special step to restore the dependency cache
15 | # Read about caching dependencies: https://circleci.com/docs/2.0/caching/
16 | key: dependency-cache-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
17 | - run:
18 | name: Install Dependencies
19 | command: npm ci
20 | - save_cache: # special step to save the dependency cache
21 | key: dependency-cache-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
22 | paths:
23 | - ./node_modules
24 | - run:
25 | name: Running E2E tests
26 | command: npm run test:ci
27 | - store_artifacts:
28 | path: cypress/videos
29 | - store_artifacts:
30 | path: cypress/screenshots
31 | - store_artifacts:
32 | path: cypress/snapshots
33 |
--------------------------------------------------------------------------------
/.github/main.workflow:
--------------------------------------------------------------------------------
1 | workflow "New workflow" {
2 | on = "push"
3 | resolves = ["Build"]
4 | }
5 |
6 | action "install" {
7 | uses = "actions/npm@e7aaefed7c9f2e83d493ff810f17fa5ccd7ed437"
8 | runs = "npm"
9 | args = "install"
10 | }
11 |
12 | action "Build" {
13 | uses = "actions/npm@e7aaefed7c9f2e83d493ff810f17fa5ccd7ed437"
14 | needs = ["install"]
15 | runs = "npm"
16 | args = "run build"
17 | }
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 | /cypress/screenshots
11 | /cypress/videos
12 | __diff_output__
13 |
14 | # production
15 | /build
16 |
17 | # misc
18 | .DS_Store
19 | .vscode
20 | .env.local
21 | .env.development.local
22 | .env.test.local
23 | .env.production.local
24 | .eslintcache
25 |
26 | npm-debug.log*
27 | yarn-debug.log*
28 | yarn-error.log*
29 |
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Christoph Benjamin Weber
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | [](https://circleci.com/gh/kriswep/cra-tailwindcss-in-js)
4 |
5 | It shows how you could setup [Tailwind CSS](https://tailwindcss.com/), a utility-first css framework, in an CRA environment with styled components and babel macros. Read more about the setup steps and benefits using [Tailwind and css-in-js combined](https://wetainment.com/articles/tailwind-css-in-js/).
6 |
7 | *Updated to work with Tailwind version 1!*
8 |
9 | ## Available Scripts
10 |
11 | In the project directory, you can run:
12 |
13 | ### `npm start`
14 |
15 | Runs the app in the development mode.
16 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
17 |
18 | The page will reload if you make edits.
19 | You will also see any lint errors in the console.
20 |
21 | ### `npm test`
22 |
23 | Launches the test runner in the interactive watch mode.
24 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
25 |
26 | ### `npm run build`
27 |
28 | Builds the app for production to the `build` folder.
29 | It correctly bundles React in production mode and optimizes the build for the best performance.
30 |
31 | The build is minified and the filenames include the hashes.
32 | Your app is ready to be deployed!
33 |
34 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
35 |
36 | ### `npm run eject`
37 |
38 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
39 |
40 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
41 |
42 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
43 |
44 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
45 |
46 | ## Learn More
47 |
48 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
49 |
50 | To learn React, check out the [React documentation](https://reactjs.org/).
51 |
52 | ### Code Splitting
53 |
54 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
55 |
56 | ### Analyzing the Bundle Size
57 |
58 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
59 |
60 | ### Making a Progressive Web App
61 |
62 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
63 |
64 | ### Advanced Configuration
65 |
66 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
67 |
68 | ### Deployment
69 |
70 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
71 |
72 | ### `npm run build` fails to minify
73 |
74 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
75 |
--------------------------------------------------------------------------------
/babel-plugin-macros.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | tailwind: {
3 | config: './src/tailwind.config.js', // if you added a config file
4 | styled: 'styled-components/macro'
5 | }
6 | }
--------------------------------------------------------------------------------
/cypress.json:
--------------------------------------------------------------------------------
1 | {
2 | "baseUrl": "http://localhost:3000",
3 | "integrationFolder": "cypress/e2e"
4 | }
5 |
--------------------------------------------------------------------------------
/cypress/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": ["cypress"],
3 | "env": {
4 | "cypress/globals": true
5 | }
6 | }
--------------------------------------------------------------------------------
/cypress/e2e/App.spec.js:
--------------------------------------------------------------------------------
1 | describe('The App should be styled', function() {
2 | it('successfully loads styled', function() {
3 | cy.visit('/');
4 | cy.matchImageSnapshot();
5 | })
6 | })
--------------------------------------------------------------------------------
/cypress/plugins/index.js:
--------------------------------------------------------------------------------
1 | // ***********************************************************
2 | // This example plugins/index.js can be used to load plugins
3 | //
4 | // You can change the location of this file or turn off loading
5 | // the plugins file with the 'pluginsFile' configuration option.
6 | //
7 | // You can read more here:
8 | // https://on.cypress.io/plugins-guide
9 | // ***********************************************************
10 |
11 | const {
12 | addMatchImageSnapshotPlugin,
13 | } = require('cypress-image-snapshot/plugin');
14 |
15 | // This function is called when a project is opened or re-opened (e.g. due to
16 | // the project's config changing)
17 |
18 | module.exports = (on, config) => {
19 | // `on` is used to hook into various events Cypress emits
20 | // `config` is the resolved Cypress config
21 | addMatchImageSnapshotPlugin(on, config);
22 | };
--------------------------------------------------------------------------------
/cypress/snapshots/All Specs/The App should be styled -- successfully loads styled.snap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriswep/cra-tailwindcss-in-js/c3920d859181bc246929b7010c1e52a9cd4997a7/cypress/snapshots/All Specs/The App should be styled -- successfully loads styled.snap.png
--------------------------------------------------------------------------------
/cypress/snapshots/App.spec.js/The App should be styled -- successfully loads styled.snap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriswep/cra-tailwindcss-in-js/c3920d859181bc246929b7010c1e52a9cd4997a7/cypress/snapshots/App.spec.js/The App should be styled -- successfully loads styled.snap.png
--------------------------------------------------------------------------------
/cypress/support/commands.js:
--------------------------------------------------------------------------------
1 | // ***********************************************
2 | // This example commands.js shows you how to
3 | // create various custom commands and overwrite
4 | // existing commands.
5 | //
6 | // For more comprehensive examples of custom
7 | // commands please read more here:
8 | // https://on.cypress.io/custom-commands
9 | // ***********************************************
10 | //
11 | //
12 | // -- This is a parent command --
13 | // Cypress.Commands.add("login", (email, password) => { ... })
14 | //
15 | //
16 | // -- This is a child command --
17 | // Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18 | //
19 | //
20 | // -- This is a dual command --
21 | // Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22 | //
23 | //
24 | // -- This is will overwrite an existing command --
25 | // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
26 |
27 | import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
28 |
29 | addMatchImageSnapshotCommand({
30 | failureThreshold: 0.006,
31 | failureThresholdType: 'percent',
32 | customDiffConfig: { threshold: 0.0 },
33 | capture: 'viewport',
34 | });
35 |
--------------------------------------------------------------------------------
/cypress/support/index.js:
--------------------------------------------------------------------------------
1 | // ***********************************************************
2 | // This example support/index.js is processed and
3 | // loaded automatically before your test files.
4 | //
5 | // This is a great place to put global configuration and
6 | // behavior that modifies Cypress.
7 | //
8 | // You can change the location of this file or turn off
9 | // automatically serving support files with the
10 | // 'supportFile' configuration option.
11 | //
12 | // You can read more here:
13 | // https://on.cypress.io/configuration
14 | // ***********************************************************
15 |
16 | // Import commands.js using ES2015 syntax:
17 | import './commands'
18 |
19 | // Alternatively you can use CommonJS syntax:
20 | // require('./commands')
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cra-tailwindcss-in-js",
3 | "version": "1.0.0",
4 | "private": true,
5 | "dependencies": {
6 | "react": "18.2.0",
7 | "react-dom": "18.2.0",
8 | "react-scripts": "4.0.3",
9 | "styled-components": "5.3.5"
10 | },
11 | "devDependencies": {
12 | "cypress": "9.7.0",
13 | "cypress-image-snapshot": "4.0.1",
14 | "eslint-plugin-cypress": "2.12.1",
15 | "start-server-and-test": "1.14.0",
16 | "tailwind.macro": "1.0.0-alpha.10"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "eject": "react-scripts eject",
22 | "test": "cypress open",
23 | "test:ci": "start-server-and-test start http://localhost:3000 cy:run",
24 | "cy:open": "cypress open",
25 | "cy:run": "cypress run",
26 | "cy:updateSnapshots": "cypress run --env updateSnapshots=true"
27 | },
28 | "eslintConfig": {
29 | "extends": "react-app"
30 | },
31 | "browserslist": [
32 | ">0.2%",
33 | "not dead",
34 | "not ie <= 11",
35 | "not op_mini all"
36 | ]
37 | }
38 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriswep/cra-tailwindcss-in-js/c3920d859181bc246929b7010c1e52a9cd4997a7/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |