Skip to content

Commit 34cf9e7

Browse files
docs/issue 188 built in TypeScript support (#198)
1 parent ac50ce2 commit 34cf9e7

16 files changed

Lines changed: 421 additions & 162 deletions

File tree

netlify.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
[[redirects]]
1212
status = 302
1313
from = "/discord/"
14-
to = "https://discord.gg/dmDmjFCKuH"
14+
to = "https://discord.gg/dmDmjFCKuH"
15+
16+
[[redirects]]
17+
status = 301
18+
from = "/docs/plugins/typescript/"
19+
to = "/docs/resources/typescript/"

src/pages/docs/content-as-data/collections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ tocHeading: 2
66

77
# Collections
88

9-
Collections are a feature in Greenwood by which you can use [frontmatter](/docs/resources/markdown/#frontmatter) to group pages that can then be referenced through [JavaScript](/docs/content-as-data/data-client/) or [active frontmatter](/docs/content-as-data/active-frontmatter/).
9+
Collections are a feature in Greenwood by which you can use [frontmatter](/docs/resources/markdown/#frontmatter) to group pages that can then be referenced through [JavaScript](/docs/content-as-data/data-client/) or [active frontmatter](/docs/content-as-data/active-frontmatter/). This can be a useful way to group pages for things like navigation menus based on the content in your pages directory.
1010

11-
This can be a useful way to group pages for things like navigation menus based on the content in your pages directory.
11+
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
1212

1313
## Usage
1414

src/pages/docs/content-as-data/data-client.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ tocHeading: 2
66

77
# Data Client
88

9-
To access your content as data with Greenwood, there are three pre-made APIs you can use, based on your use case. These are isomorphic in that they will consume live data during development, and statically build out each query at build time to its own JSON file that will be fetched client side without needing a. This way, you can serialize and / or hydrate from this data as needed based on your needs.
9+
To access your content as data with Greenwood, there are three pre-made APIs you can use, based on your use case. These are isomorphic in that they will consume live data during development, and statically build out each query at build time to its own JSON file that will be fetched client side without needing a server. This way, you can serialize and / or hydrate from this data as needed based on your needs.
10+
11+
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
1012

1113
> This feature works best when used for build time templating when combined with the [**static** optimization](/docs/reference/configuration/#optimization) setting.
1214

src/pages/docs/plugins/css-modules.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: CSS Modules
33
label: CSS Modules
44
layout: docs
5-
order: 3
5+
order: 2
66
tocHeading: 2
77
---
88

@@ -123,3 +123,46 @@ And reference that in your (Light DOM) HTML based Web Component:
123123
<!-- prettier-ignore-end -->
124124

125125
From there, Greenwood will scope your CSS class names by prefixing them with the filename and a hash of the contents, inline that into a `<style>` tag in the HTML, and then strip the reference to the _module.css_ file from your JavaScript file.
126+
127+
## Types
128+
129+
Types should automatically be inferred through this package's exports map, but can be referenced explicitly in both JavaScript (JSDoc) and TypeScript files if needed.
130+
131+
<!-- prettier-ignore-start -->
132+
133+
<app-ctc-block variant="snippet">
134+
135+
```js
136+
/** @type {import('@greenwood/plugin-css-modules').CssModulesPlugin} */
137+
```
138+
139+
</app-ctc-block>
140+
141+
<!-- prettier-ignore-end -->
142+
143+
<!-- prettier-ignore-start -->
144+
145+
<app-ctc-block variant="snippet">
146+
147+
```ts
148+
import type { CssModulesPlugin } from '@greenwood/plugin-css-modules';
149+
```
150+
151+
</app-ctc-block>
152+
153+
<!-- prettier-ignore-end -->
154+
155+
To support typing of `.module.css` imports, you can add this type definition to your project:
156+
157+
<app-ctc-block variant="snippet" heading="src/types.d.ts">
158+
159+
```ts
160+
declare module "*.module.css" {
161+
const styles: { [className: string]: string };
162+
export default styles;
163+
}
164+
```
165+
166+
</app-ctc-block>
167+
168+
<!-- prettier-ignore-end -->

src/pages/docs/plugins/index.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ tocHeading: 2
1313
## Featured
1414

1515
- [Lit SSR](/docs/plugins/lit-ssr/) - For Lit users, a custom renderer plugin to support Lit+SSR
16-
- [TypeScript](/docs/plugins/typescript/) - A plugin for transforming files written in TypeScript
1716
- [PostCSS](/docs/plugins/postcss/) - Leverage PostCSS plugins, like [Tailwind](/guides/ecosystem/tailwind/)
1817
- [CSS Modules](/docs/plugins/css-modules/) - Support for [CSS Modules](https://github.com/css-modules/css-modules) ™️ syntax
1918
- [Raw Loader](/docs/plugins/raw/) - Import arbitrary text files as ESM
@@ -25,7 +24,7 @@ Below is the official list of supported first-party plugins available by the Gre
2524
<br>
2625

2726
| Name | Description |
28-
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
27+
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- | --- |
2928
| [Babel](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-babel) | Use [**Babel**](https://babeljs.io/) plugins, presets, and configuration in your project. |
3029
| [HTML Include](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-include-html) | Inspired by the original [HTML Imports spec](https://www.html5rocks.com/en/tutorials/webcomponents/imports/). |
3130
| [Import Raw](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-import-raw) | Enables usage of ESM syntax for loading arbitrary file contents as a string. |
@@ -34,6 +33,5 @@ Below is the official list of supported first-party plugins available by the Gre
3433
| [Netlify](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-adapter-netlify) | Deploy serverless and edge functions to [**Netlify**](https://www.netlify.com/). |
3534
| [Polyfills](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-polyfills) | Web Component related polyfills for older browsers. |
3635
| [PostCSS](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-postcss) | Allows usage of [**PostCSS**](https://postcss.org/) plugins and configuration in your project. |
37-
| [Puppeteer](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-renderer-puppeteer) | A rendering plugin to support prerendering a Greenwood project using Puppeteer. |
38-
| [TypeScript](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-typescript) | Allows usage of [**TypeScript**](https://www.typescriptlang.org/) syntax. |
36+
| [Puppeteer](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-renderer-puppeteer) | A rendering plugin to support prerendering a Greenwood project using Puppeteer. | |
3937
| [Vercel](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-adapter-vercel) | Deploy serverless and edge functions with [**Vercel**](https://vercel.com/). |

src/pages/docs/plugins/lit-ssr.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Lit SSR
33
label: Lit SSR
44
layout: docs
5-
order: 2
5+
order: 1
66
tocHeading: 2
77
---
88

@@ -123,3 +123,33 @@ Below is an example of generating a page of LitElement based Web Components:
123123
<!-- prettier-ignore-end -->
124124

125125
> Keep in mind you will need to make sure your Lit Web Components are isomorphic and [properly leveraging `LitElement`'s lifecycles](https://github.com/lit/lit/tree/main/packages/labs/ssr#notes-and-limitations) and browser / Node APIs accordingly for maximum compatibility and portability.
126+
127+
## Types
128+
129+
Types should automatically be inferred through this package's exports map, but can be referenced explicitly in both JavaScript (JSDoc) and TypeScript files if needed.
130+
131+
<!-- prettier-ignore-start -->
132+
133+
<app-ctc-block variant="snippet">
134+
135+
```js
136+
/** @type {import('@greenwood/plugin-renderer-lit').LitRendererPlugin} */
137+
```
138+
139+
</app-ctc-block>
140+
141+
<!-- prettier-ignore-end -->
142+
143+
<!-- prettier-ignore-start -->
144+
145+
<app-ctc-block variant="snippet">
146+
147+
```ts
148+
import type { LitRendererPlugin } from '@greenwood/plugin-renderer-lit';
149+
```
150+
151+
</app-ctc-block>
152+
153+
<!-- prettier-ignore-end -->
154+
155+
> If you're using Lit with TypeScript, you'll most likely be using [their decorators](https://lit.dev/docs/components/decorators/#compiler-output-considerations), If so, make sure to enable the [`useTsc` option](/docs/reference/configuration/#use-typescript-compiler) in your Greenwood configuration file.

src/pages/docs/plugins/postcss.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: PostCSS
33
label: PostCSS
44
layout: docs
5-
order: 5
5+
order: 4
66
tocHeading: 2
77
---
88

@@ -118,3 +118,31 @@ and see the results of the plugin in the generated styles
118118
}
119119
}
120120
```
121+
122+
## Types
123+
124+
Types should automatically be inferred through this package's exports map, but can be referenced explicitly in both JavaScript (JSDoc) and TypeScript files if needed.
125+
126+
<!-- prettier-ignore-start -->
127+
128+
<app-ctc-block variant="snippet">
129+
130+
```js
131+
/** @type {import('@greenwood/plugin-postcss').PostCssPlugin} */
132+
```
133+
134+
</app-ctc-block>
135+
136+
<!-- prettier-ignore-end -->
137+
138+
<!-- prettier-ignore-start -->
139+
140+
<app-ctc-block variant="snippet">
141+
142+
```ts
143+
import type { PostCssPlugin } from '@greenwood/plugin-postcss';
144+
```
145+
146+
</app-ctc-block>
147+
148+
<!-- prettier-ignore-end -->

src/pages/docs/plugins/raw.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: docs
3-
order: 4
3+
order: 3
44
tocHeading: 2
55
---
66

@@ -111,3 +111,46 @@ Or perfect for statically embedding SVGs into HTML:
111111
</app-ctc-block>
112112

113113
<!-- prettier-ignore-end -->
114+
115+
## Types
116+
117+
Types should automatically be inferred through this package's exports map, but can be referenced explicitly in both JavaScript (JSDoc) and TypeScript files if needed.
118+
119+
<!-- prettier-ignore-start -->
120+
121+
<app-ctc-block variant="snippet">
122+
123+
```js
124+
/** @type {import('@greenwood/plugin-import-raw').ImportRawPlugin} */
125+
```
126+
127+
</app-ctc-block>
128+
129+
<!-- prettier-ignore-end -->
130+
131+
<!-- prettier-ignore-start -->
132+
133+
<app-ctc-block variant="snippet">
134+
135+
```ts
136+
import type { ImportRawPlugin } from '@greenwood/plugin-import-raw';
137+
```
138+
139+
</app-ctc-block>
140+
141+
<!-- prettier-ignore-end -->
142+
143+
To support typing of raw file imports, you can add this type definition to your project:
144+
145+
<app-ctc-block variant="snippet" heading="src/types.d.ts">
146+
147+
```ts
148+
declare module "*?type=raw" {
149+
const content: string;
150+
export default content;
151+
}
152+
```
153+
154+
</app-ctc-block>
155+
156+
<!-- prettier-ignore-end -->

src/pages/docs/plugins/typescript.md

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)