Skip to content

Commit aeb9167

Browse files
committed
Update Readme
1 parent f7b6108 commit aeb9167

3 files changed

Lines changed: 52 additions & 113 deletions

File tree

README.md

Lines changed: 44 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# esbuild-plugin-react18-css
22

3-
[![test](https://github.com/react18-tools/esbuild-plugin-react18-css/actions/workflows/test.yml/badge.svg)](https://github.com/react18-tools/esbuild-plugin-react18-css/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/react18-tools/esbuild-plugin-react18-css/maintainability) [![codecov](https://codecov.io/gh/react18-tools/esbuild-plugin-react18-css/graph/badge.svg)](https://codecov.io/gh/react18-tools/esbuild-plugin-react18-css) [![Version](https://img.shields.io/npm/v/esbuild-plugin-react18-css.svg?colorB=green)](https://www.npmjs.com/package/esbuild-plugin-react18-css) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/dt/esbuild-plugin-react18-css.svg)](https://www.npmjs.com/package/esbuild-plugin-react18-css) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/esbuild-plugin-react18-css) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/from-referrer/)
3+
[![test](https://github.com/react18-tools/esbuild-plugin-react18-css/actions/workflows/test.yml/badge.svg)](https://github.com/react18-tools/esbuild-plugin-react18-css/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/4a09ba9315f3296c1524/maintainability)](https://codeclimate.com/github/react18-tools/esbuild-plugin-react18-css/maintainability) [![codecov](https://codecov.io/gh/react18-tools/esbuild-plugin-react18-css/graph/badge.svg)](https://codecov.io/gh/react18-tools/esbuild-plugin-react18-css) [![Version](https://img.shields.io/npm/v/esbuild-plugin-react18-css.svg?colorB=green)](https://www.npmjs.com/package/esbuild-plugin-react18-css) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/dt/esbuild-plugin-react18-css.svg)](https://www.npmjs.com/package/esbuild-plugin-react18-css) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/esbuild-plugin-react18-css) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/from-referrer/)
44

55
> [Featured packages built with this template.](./FEATURED.md)
66
77
## Features
88

9-
✅ Fully Treeshakable (import from esbuild-plugin-react18-css/client/component)
9+
✅ ESBuild plugin to handle CSS/SCSS modules, autoprefixer, etc.
10+
11+
✅ Create fully treeshakable libraries (import from esbuild-plugin-react18-css/client/component)
12+
13+
✅ Use CSS/SCSS modules - automatically converted to BEM like CSS
14+
15+
✅ fully treeshakable CSS - import only the CSS files your users need
1016

1117
✅ Full TypeScript Support
1218

@@ -34,126 +40,58 @@ or
3440
$ yarn add esbuild-plugin-react18-css
3541
```
3642

43+
## use with `tsup`
3744

45+
```ts
46+
// tsup.config.ts or tsup.config.js
47+
import { defineConfig } from "tsup";
48+
import cssPlugin from "esbuild-plugin-react18-css";
3849

39-
40-
## Getting started:
41-
42-
Click on the `"Use this template"` button to customize it for your next JavaScript/TypeScript/React/Vue/Next.js library or project.
43-
44-
## What's Different?
45-
46-
Compared to the default scaffold from create-turbo, this template offers:
47-
48-
- Unit tests with `vitest`
49-
- Build setup with `tsup` and `esbuild-react18-useclient` Supports React Server components out of the box
50-
- **Automatic file generation**
51-
- just run `yarn turbo gen` and follow the prompts to auto generate your new component with test file and dependency linking
52-
- follow best practices automatically
53-
- GitHub actions/workflows to auto publish your package when version changes
54-
- GitHub action/workflow + preinstall scripts to automatically rebrand your repo on creation
55-
56-
## Step by Step Instructions and Checklist
57-
58-
- [ ] Star [this repo](https://github.com/react18-tools/esbuild-plugin-react18-css/) so that you and others can find it more easily for your next projects. It also helps me understand that people are using this repo so that I can maintain the repo and the documentation well.
59-
60-
61-
62-
63-
- [ ] Install and setup Node.js and IDE (I prefer VSCode)
64-
- [ ] Install the recommended VSCode extensions - [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode), [Trello Kanban](https://marketplace.visualstudio.com/items?itemName=mayank1513.trello-kanban-task-board)
65-
- [ ] Install dependencies using `pnpm`
66-
- [ ] If you don't have `pnpm` installed, run `npm i -g pnpm` to install `pnpm` -> run `pnpm setup` to set up `pnpm` for global installations
67-
- [ ] Run `pnpm i` to install dependencies and `preinstall` script will automatically touch up workflows and create a commit
68-
- [ ] Run `pnpm i -g turbo` to install `turbo` globally (Sometime due to `TypeScript` and `Plop` version conflicts code generation requires global `turbo`).
69-
- [ ] Run `turbo gen react-component`, and follow prompts to generate server or client components for your library
70-
- [ ] Use `snake-case` for your component name - it will be automatically converted to `PascalCase`
71-
- [ ] Your component and test files will be created in `**/src/client/` or `**/src/server/` directory depending on whether you choose `client` or `server` component
72-
- [ ] run `node scope.js` from the root directory if you want to publish scoped pacckage.
73-
- [ ] We assumed that your npm user name is same as your GitHub account or organization username.
74-
- [ ] Please make sure `owner` is set to your <npmjs.com> username before running the above command.
75-
- [ ] Set up `CodeCov`
76-
- [ ] Visit codecov and setup your repo
77-
- [ ] Create [repository secret](https://github.com/react18-tools/esbuild-plugin-react18-css/settings/secrets/actions) for `CODECOV_TOKEN`
78-
- [ ] Set up `CodeClimate`
79-
- [ ] Visit CodeClimate and setup your repo
80-
- [ ] Create [repository secret](https://github.com/react18-tools/esbuild-plugin-react18-css/settings/secrets/actions) for `CC_TEST_REPORTER_ID`
81-
- [ ] add `*.test.*` to ignore patterns on the website
82-
- [ ] update code climate badge
83-
- [ ] Add `NPM_AUTH_TOKEN` to repository secrets to automate publishing package
84-
- [ ] login to your [`npm` account](https://www.npmjs.com/login) and create automation token
85-
- [ ] Create a new repository secrets `NPM_AUTH_TOKEN`
86-
- [ ] Update description in `lib/esbuild-plugin-react18-css/package.json`
87-
- [ ] Update Repo Stats by visiting and setting up [repobeats](https://repobeats.axiom.co/)
88-
- [ ] Create your library and update examples
89-
- [ ] Update README
90-
- [ ] Setup GitHub pages to deploy docs
91-
- [ ] Go to [repo settings](https://github.com/react18-tools/esbuild-plugin-react18-css/settings/pages) -> pages (On left panel); Select deploy from a branch; Then Select `main` and `/docs`
92-
- [ ] Push your changes/Create PR and see your library being automatically tested and published
93-
- [ ] Optionally deploy your example(s) to Vercel.
94-
- [ ] Update sponsorship urls.
95-
- [ ] You are most welcome to star this template, contribute, and/or sponsor the `terbo-repo-template` project or my other open-source work
96-
- [ ] You can also fork the `terbo-repo-template` and add your package to `packages/shared-ui/src/examples/featured.json`
97-
- [ ] If approved your package will be automatically added to FEATURED.md and also published on the home page of this repo.
98-
99-
## What's inside?
100-
101-
### Utilities
102-
103-
This Turborepo template includes pre-configured tools:
104-
105-
- [TypeScript](https://www.typescriptlang.org/) for static type checking
106-
- [ESLint](https://eslint.org/) for code linting
107-
- [Prettier](https://prettier.io) for code formatting
108-
- Plop based code generator for scaffolding new components
109-
- Automatically rebrand this template to match your repo name
110-
111-
### Apps and Packages
112-
113-
This Turborepo includes the following packages/examples/lib:
114-
115-
- `nextjs`: a [Next.js](https://nextjs.org/) app
116-
- `vite`: a [Vite.js](https://vitest.dev) app
117-
- `fork-me`: a React component library shared by both `Next.js` and `Vite` examples
118-
- `eslint-config-custom`: ESLint configurations (includes `eslint-config-next` and `eslint-config-prettier`)
119-
- `tsconfig`: `tsconfig.json`s used throughout the monorepo
120-
121-
Each package/example is 100% [TypeScript](https://www.typescriptlang.org/).
122-
123-
### Build
124-
125-
To build all apps and packages, run the following command:
126-
127-
```
128-
cd esbuild-plugin-react18-css
129-
pnpm build
50+
export default defineConfig(options => ({
51+
...
52+
esbuildPlugins:[cssPlugin()]
53+
}));
13054
```
13155

132-
### Develop
56+
## use with esbuild
13357

134-
To develop all apps and packages, run the following command:
58+
```ts
59+
import cssPlugin from "esbuild-plugin-react18-css";
13560

61+
esbuild.build({
62+
...
63+
plugins: [cssPlugin()],
64+
});
13665
```
137-
cd esbuild-plugin-react18-css
138-
pnpm dev
66+
67+
## CSSPluginOptions
68+
69+
```tsx
70+
interface CSSPluginOptions {
71+
/** by default name is generated without hash so that it is easier and reliable for library users to override some CSS*/
72+
generateScopedName?: string | ((className: string, filename: string, css: string) => string);
73+
/** set skipAutoPrefixer to true to disable autoprefixer */
74+
skipAutoPrefixer?: boolean;
75+
/** global CSS class prefix. @defaultValue "" */
76+
globalPrefix?: string;
77+
}
13978
```
14079

141-
## Useful Links
80+
### generateScopedName
81+
82+
It can be a string like `[name]__[local]___[hash:base64:5]` or `[name]__[local]` or `my-prefix__[name]__[local]`
14283

143-
Learn more about the power of Turborepo:
84+
The functions arguments are as follows.
14485

145-
- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
146-
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
147-
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
148-
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
149-
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
150-
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)
86+
- css: the entire css file content
87+
- className: className from css file for the specific class
88+
- fileName: absolute fileName
15189

15290
### 🤩 Don't forger to star [this repo](https://github.com/react18-tools/esbuild-plugin-react18-css)!
15391

15492
Want hands-on course for getting started with Turborepo? Check out [React and Next.js with TypeScript](https://mayank-chaudhari.vercel.app/courses/react-and-next-js-with-typescript) and [The Game of Chess with Next.js, React and TypeScrypt](https://www.udemy.com/course/game-of-chess-with-nextjs-react-and-typescrypt/?referralCode=851A28F10B254A8523FE)
15593

156-
![Repo Stats](https://repobeats.axiom.co/api/embed/2ef1a24385037998386148afe5a98ded6006f410.svg "Repobeats analytics image")
94+
![Repo Stats](https://repobeats.axiom.co/api/embed/b9f60aadc635649d8a66039094bcb26b5ccea1c1.svg "Repobeats analytics image")
15795

15896
## License
15997

lib/esbuild-plugin-react18-css/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
44
"private": false,
55
"version": "0.0.0",
6-
"description": "An intuitive React.js fork me ribbon component for promoting open source project forks.",
6+
"description": "ESBuild plugin to handle CSS/SCSS modules, autoprefixer, etc.",
77
"main": "dist/index.js",
88
"types": "dist/index.d.ts",
99
"repository": {
@@ -53,6 +53,7 @@
5353
"esbuild-plugin",
5454
"typescript",
5555
"javascript",
56+
"autoprefixer",
5657
"css-module",
5758
"postcss",
5859
"esbuild",

lib/esbuild-plugin-react18-css/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { compile } from "sass";
88

99
const uuid = () => (Date.now() * Math.random()).toString(36).slice(0, 8);
1010

11-
interface CSSModulePluginOptions {
12-
/** by default name is generated without hash */
13-
generateScopedName?: string | ((name: string, filename: string, css: string) => string);
11+
interface CSSPluginOptions {
12+
/** by default name is generated without hash so that it is easier and reliable for library users to override some CSS */
13+
generateScopedName?: string | ((className: string, filename: string, css: string) => string);
1414
/** set skipAutoPrefixer to true to disable autoprefixer */
1515
skipAutoPrefixer?: boolean;
1616
/** global CSS class prefix. @defaultValue "" */
@@ -47,7 +47,7 @@ function generateCombinedCSS(result: BuildResult) {
4747
});
4848
}
4949

50-
function applyAutoPrefixer(build: PluginBuild, options: CSSModulePluginOptions, write?: boolean) {
50+
function applyAutoPrefixer(build: PluginBuild, options: CSSPluginOptions, write?: boolean) {
5151
build.onEnd(async result => {
5252
if (!options.skipAutoPrefixer) {
5353
for (const f of result.outputFiles?.filter(f => f.path.match(/\.css$/)) || []) {
@@ -75,7 +75,7 @@ function handleScss(build: PluginBuild) {
7575
}));
7676
}
7777

78-
function handleModules(build: PluginBuild, { generateScopedName }: CSSModulePluginOptions) {
78+
function handleModules(build: PluginBuild, { generateScopedName }: CSSPluginOptions) {
7979
const namespace = "scss-module";
8080
const filter = /\.module\.(sc|sa|c)ss/;
8181
build.onResolve({ filter, namespace: "file" }, args => ({
@@ -121,7 +121,7 @@ function handleModules(build: PluginBuild, { generateScopedName }: CSSModulePlug
121121
}));
122122
}
123123

124-
const cssPlugin: (options?: CSSModulePluginOptions) => Plugin = (options = {}) => ({
124+
const cssPlugin: (options?: CSSPluginOptions) => Plugin = (options = {}) => ({
125125
name: "esbuild-plugin-react18-css-" + uuid(),
126126
setup(build): void {
127127
const write = build.initialOptions.write;

0 commit comments

Comments
 (0)