|
| 1 | +# @tw-in-js/typescript-plugin |
| 2 | + |
| 3 | +> TypeScript language service plugin that adds IntelliSense for tailwindjs |
| 4 | +
|
| 5 | +[](https://github.com/tw-in-js/core/blob/main/LICENSE) |
| 6 | +[](https://www.npmjs.com/package/@tw-in-js/typescript-plugin) |
| 7 | +[](https://github.com/tw-in-js/typescript-plugin) |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +<!-- prettier-ignore-start --> |
| 12 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 13 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 14 | + |
| 15 | + |
| 16 | +- [Features](#features) |
| 17 | +- [Installation](#installation) |
| 18 | +- [Usage](#usage) |
| 19 | +- [Configuration](#configuration) |
| 20 | +- [Contribute](#contribute) |
| 21 | +- [License](#license) |
| 22 | + |
| 23 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 24 | +<!-- prettier-ignore-end --> |
| 25 | + |
| 26 | +## Features |
| 27 | + |
| 28 | +Provides editor support for ```tw`...```` tagged template syntax including: |
| 29 | + |
| 30 | +- Autocomplete for tailwind, beamwind and oceanwin classes |
| 31 | +- Warnings on unknown classes |
| 32 | +- Quick fixes for misspelled property names. |
| 33 | + |
| 34 | +## Installation |
| 35 | + |
| 36 | +```sh |
| 37 | +npm install --save-dev @tw-in-js/typescript-plugin |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +This plugin requires TypeScript 2.4 or later. It can provide intellisense in both JavaScript and TypeScript files within any editor that uses TypeScript to power their language features. This includes [VS Code](https://code.visualstudio.com), [Sublime with the TypeScript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin), [Atom with the TypeScript plugin](https://atom.io/packages/atom-typescript), [Visual Studio](https://www.visualstudio.com), and others. |
| 43 | + |
| 44 | +### With VS Code |
| 45 | + |
| 46 | +Just install the [VS Code tailwindjs extension](https://github.com/tw-in-js/core/packages/vscode). This extension adds syntax highlighting and IntelliSense for styled components in JavaScript and TypeScript files. |
| 47 | + |
| 48 | +If you are using a [workspace version of TypeScript](<(https://code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions)>) however, you must manually install the plugin along side the version of TypeScript in your workspace. |
| 49 | + |
| 50 | +Then add a `plugins` section to your [`tsconfig.json`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or [`jsconfig.json`](https://code.visualstudio.com/Docs/languages/javascript#_javascript-project-jsconfigjson) |
| 51 | + |
| 52 | +```json |
| 53 | +{ |
| 54 | + "compilerOptions": { |
| 55 | + "plugins": [ |
| 56 | + { |
| 57 | + "name": "@tw-in-js/typescript-plugin" |
| 58 | + } |
| 59 | + ] |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +Finally, run the `Select TypeScript version` command in VS Code to switch to use the workspace version of TypeScript for VS Code's JavaScript and TypeScript language support. You can find more information about managing typescript versions [in the VS Code documentation](https://code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions). |
| 65 | + |
| 66 | +### With Sublime |
| 67 | + |
| 68 | +This plugin works with the [Sublime TypeScript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin). |
| 69 | + |
| 70 | +And configure Sublime to use the workspace version of TypeScript by [setting the `typescript_tsdk`](https://github.com/Microsoft/TypeScript-Sublime-Plugin#note-using-different-versions-of-typescript) setting in Sublime: |
| 71 | + |
| 72 | +```json |
| 73 | +{ |
| 74 | + "typescript_tsdk": "/path/to/the/project/node_modules/typescript/lib" |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +Finally add a `plugins` section to your [`tsconfig.json`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or [`jsconfig.json`](https://code.visualstudio.com/Docs/languages/javascript#_javascript-project-jsconfigjson) and restart Sublime. |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "compilerOptions": { |
| 83 | + "plugins": [ |
| 84 | + { |
| 85 | + "name": "@tw-in-js/typescript-plugin" |
| 86 | + } |
| 87 | + ] |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### With Atom |
| 93 | + |
| 94 | +This plugin works with the [Atom TypeScript plugin](https://atom.io/packages/atom-typescript). |
| 95 | + |
| 96 | +Then add a `plugins` section to your [`tsconfig.json`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or [`jsconfig.json`](https://code.visualstudio.com/Docs/languages/javascript#_javascript-project-jsconfigjson) and restart Atom. |
| 97 | + |
| 98 | +```json |
| 99 | +{ |
| 100 | + "compilerOptions": { |
| 101 | + "plugins": [ |
| 102 | + { |
| 103 | + "name": "@tw-in-js/typescript-plugin" |
| 104 | + } |
| 105 | + ] |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +To get sytnax highlighting for styled strings in Atom, consider installing the [language-babel](https://atom.io/packages/language-babel) extension. |
| 111 | + |
| 112 | +### With Visual Studio |
| 113 | + |
| 114 | +This plugin works [Visual Studio 2017](https://www.visualstudio.com) using the TypeScript 2.5+ SDK. |
| 115 | + |
| 116 | +Then add a `plugins` section to your [`tsconfig.json`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html). |
| 117 | + |
| 118 | +```json |
| 119 | +{ |
| 120 | + "compilerOptions": { |
| 121 | + "plugins": [ |
| 122 | + { |
| 123 | + "name": "@tw-in-js/typescript-plugin" |
| 124 | + } |
| 125 | + ] |
| 126 | + } |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +Then reload your project to make sure the plugin has been loaded properly. Note that `jsconfig.json` projects are currently not supported in VS. |
| 131 | + |
| 132 | +## Configuration |
| 133 | + |
| 134 | +### Tags |
| 135 | + |
| 136 | +This plugin adds IntelliSense to any template literal [tagged](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) with `tw`, `ow` or `bw`: |
| 137 | + |
| 138 | +```js |
| 139 | +import { bw } from 'beamwind' |
| 140 | + |
| 141 | +bw` |
| 142 | + sm:hover:( |
| 143 | + bg-black |
| 144 | + text-white |
| 145 | + ) |
| 146 | + md:(bg-white hover:text-black) |
| 147 | +` |
| 148 | +``` |
| 149 | + |
| 150 | +You can enable IntelliSense for other tag names by configuring `"tags"`: |
| 151 | + |
| 152 | +```json |
| 153 | +{ |
| 154 | + "compilerOptions": { |
| 155 | + "plugins": [ |
| 156 | + { |
| 157 | + "name": "@tw-in-js/typescript-plugin", |
| 158 | + "tags": ["tw", "cx"] |
| 159 | + } |
| 160 | + ] |
| 161 | + } |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +Now strings tagged with either `tw` and `cx` will have IntelliSense. |
| 166 | + |
| 167 | +## Contribute |
| 168 | + |
| 169 | +Thanks for being willing to contribute! |
| 170 | + |
| 171 | +> This project is free and open-source, so if you think this project can help you or anyone else, you may [star it on GitHub](https://github.com/tw-in-js/core). Feel free to [open an issue](https://github.com/tw-in-js/core/issues) if you have any idea, question, or you've found a bug. |
| 172 | +
|
| 173 | +**Working on your first Pull Request?** You can learn how from this _free_ series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github) |
| 174 | + |
| 175 | +We are following the [Conventional Commits](https://www.conventionalcommits.org) convention. |
| 176 | + |
| 177 | +### Develop |
| 178 | + |
| 179 | +> Ensure you run at least Node v14. |
| 180 | +
|
| 181 | +Clone the repository and cd into the project directory. |
| 182 | + |
| 183 | +Run `yarn install && yarn build`. |
| 184 | + |
| 185 | +- `yarn test`: Run test suite including linting |
| 186 | +- `yarn format`: Ensure consistent code style |
| 187 | +- `yarn build`: Build the package |
| 188 | +- `yarn release`: To publish the package |
| 189 | + |
| 190 | +### Manual testing the Language service plugin |
| 191 | + |
| 192 | +You can check manually language service plugin features with our example project. |
| 193 | + |
| 194 | +``` |
| 195 | +yarn build |
| 196 | +cd dist |
| 197 | +yarn link |
| 198 | +cd project-fixtures/react-apollo-prj |
| 199 | +yarn install |
| 200 | +yarn link @tw-in-js/typescript-plugin |
| 201 | +code . # Or launch editor/IDE what you like |
| 202 | +``` |
| 203 | + |
| 204 | +Of course, you can use other editor which communicates with tsserver . |
| 205 | + |
| 206 | +## License |
| 207 | + |
| 208 | +[MIT](https://github.com/tw-in-js/typescript-plugin/blob/main/LICENSE) |
0 commit comments