|
1 | 1 | # esbuild-plugin-react18-css |
2 | 2 |
|
3 | | -[](https://github.com/react18-tools/esbuild-plugin-react18-css/actions/workflows/test.yml) [](https://codeclimate.com/github/react18-tools/esbuild-plugin-react18-css/maintainability) [](https://codecov.io/gh/react18-tools/esbuild-plugin-react18-css) [](https://www.npmjs.com/package/esbuild-plugin-react18-css) [](https://www.npmjs.com/package/esbuild-plugin-react18-css)  [](https://gitpod.io/from-referrer/) |
| 3 | +[](https://github.com/react18-tools/esbuild-plugin-react18-css/actions/workflows/test.yml) [](https://codeclimate.com/github/react18-tools/esbuild-plugin-react18-css/maintainability) [](https://codecov.io/gh/react18-tools/esbuild-plugin-react18-css) [](https://www.npmjs.com/package/esbuild-plugin-react18-css) [](https://www.npmjs.com/package/esbuild-plugin-react18-css)  [](https://gitpod.io/from-referrer/) |
4 | 4 |
|
5 | 5 | > [Featured packages built with this template.](./FEATURED.md) |
6 | 6 |
|
7 | 7 | ## Features |
8 | 8 |
|
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 |
10 | 16 |
|
11 | 17 | ✅ Full TypeScript Support |
12 | 18 |
|
|
34 | 40 | $ yarn add esbuild-plugin-react18-css |
35 | 41 | ``` |
36 | 42 |
|
| 43 | +## use with `tsup` |
37 | 44 |
|
| 45 | +```ts |
| 46 | +// tsup.config.ts or tsup.config.js |
| 47 | +import { defineConfig } from "tsup"; |
| 48 | +import cssPlugin from "esbuild-plugin-react18-css"; |
38 | 49 |
|
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 | +})); |
130 | 54 | ``` |
131 | 55 |
|
132 | | -### Develop |
| 56 | +## use with esbuild |
133 | 57 |
|
134 | | -To develop all apps and packages, run the following command: |
| 58 | +```ts |
| 59 | +import cssPlugin from "esbuild-plugin-react18-css"; |
135 | 60 |
|
| 61 | +esbuild.build({ |
| 62 | + ... |
| 63 | + plugins: [cssPlugin()], |
| 64 | +}); |
136 | 65 | ``` |
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 | +} |
139 | 78 | ``` |
140 | 79 |
|
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]` |
142 | 83 |
|
143 | | -Learn more about the power of Turborepo: |
| 84 | +The functions arguments are as follows. |
144 | 85 |
|
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 |
151 | 89 |
|
152 | 90 | ### 🤩 Don't forger to star [this repo](https://github.com/react18-tools/esbuild-plugin-react18-css)! |
153 | 91 |
|
154 | 92 | 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) |
155 | 93 |
|
156 | | - |
| 94 | + |
157 | 95 |
|
158 | 96 | ## License |
159 | 97 |
|
|
0 commit comments