Skip to content

Commit 13b8084

Browse files
update docs and deleted outdated build docs
1 parent c2db7df commit 13b8084

File tree

9 files changed

+55
-136
lines changed

9 files changed

+55
-136
lines changed

packages/cli/src/lib/resource-interface.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ResourceInterface {
99
}
1010

1111
// test if this plugin should change a relative URL from the browser to an absolute path on disk
12-
// like for node_modules/ resolution, not commonly needed
12+
// like for node_modules/ resolution. not commonly needed by most resource plugins
1313
// return true | false
1414
// eslint-disable-next-line no-unused-vars
1515
async shouldResolve(url) {
@@ -29,14 +29,14 @@ class ResourceInterface {
2929
return Promise.resolve(this.extensions.indexOf(path.extname(url)) >= 0);
3030
}
3131

32-
// return the new body and / or contentType, e.g. convert file.foo -> .js
32+
// return the new body and / or contentType, e.g. convert file.foo -> file.js
3333
// eslint-disable-next-line no-unused-vars
3434
async serve(url, headers) {
3535
return Promise.resolve({});
3636
}
3737

3838
// test if this plugin should return a new body for an already resolved resource
39-
// useful for modifying code on the fly without needing to touch the file
39+
// useful for modifying code on the fly without needing to read the file from disk
4040
// return true | false
4141
// eslint-disable-next-line no-unused-vars
4242
async shouldIntercept(url, body, headers) {
@@ -50,7 +50,7 @@ class ResourceInterface {
5050
}
5151

5252
// test if this plugin should manipulate any files prior to any final optmizations happening
53-
// ex: add a "banner" to all .js files with a timestamp of the build
53+
// ex: add a "banner" to all .js files with a timestamp of the build, or minifying files
5454
// return true | false
5555
// eslint-disable-next-line no-unused-vars
5656
async shouldOptimize(url, body) {

www/pages/docs/build.md

-116
This file was deleted.

www/pages/docs/css-and-images.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
label: 'styles-assets'
33
menu: side
44
title: 'Styles and Assets'
5-
index: 6
5+
index: 5
66
linkheadings: 3
77
---
88

www/pages/docs/front-matter.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
label: 'front-matter'
33
menu: side
44
title: 'Front Matter'
5-
index: 4
5+
index: 3
66
linkheadings: 3
77
---
88

www/pages/docs/markdown.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
label: 'markdown'
33
menu: side
44
title: 'Markdown'
5-
index: 5
5+
index: 4
66
linkheadings: 3
77
---
88

www/pages/plugins/custom-plugins.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The available plugins built and maintained by Greenwood team and contibutors hav
1414
|---|---|
1515
| [Google Analytics](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-google-analytics) | Easily add usage tracking to your site with Google Analytics. |
1616
| [Import CommonJs](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-import-commonjs) | Enables usage of `import` syntax for loading CommonJS modules from _node_modules_. |
17+
| [Import CSS](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-import-css) | Enables usage of `import` syntax for loading CSS files. |
1718
| [Polyfills](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-polyfills) | Although most modern browsers now support the APIs that make up Web Component, for older browsers use this plugin to Let Greenwood automatically take care of progressively loading polyfills for you. |
19+
| [PostCSS](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-postcss) | Allows usage of [**PostCSS**](https://postcss.org/) plugins and configuration in your project. |
1820

1921
> See something missing? Please review our [open issues](https://github.com/ProjectEvergreen/greenwood/issues), we might be [working on it](https://github.com/ProjectEvergreen/greenwood/projects)! Or if not, please request it, we would be interested to learn how you need to use Greenwod and how the team can help!

www/pages/plugins/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Greenwood aims to cater to these use cases through two approaches:
2424
### API
2525
Each plugin must return a function that has the following three properties:.
2626
- `name`: A string to give your plugin a name and used for error handling and troubleshooting.
27-
- `type`: A string to specify to Greenwood the type of plugin. Right now the current supported plugin type [`'resource'`](/plugins/resource/) and [`'plugin'`](/plugins/server/).
27+
- `type`: A string to specify to Greenwood the type of plugin. Right now the current supported plugin types are [`'resource'`](/plugins/resource/), [`'rollup'`](/plugins/rollup/), and [`'server'`](/plugins/server/).
2828
- `provider`: A function that will be invoked by Greenwood that Can accept a `compilation` param that provides read-only access to parts of Greenwood's state and configuration that can be used by a plugin.
2929

3030
Here is an example of creating a plugin in a _greenwood.config.js_.

www/pages/plugins/resource.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ Although JavaScript is loosely typed, a [resource "interface"](https://github.co
2020
const fs = require('fs');
2121
const { ResourceInterface } = require('@greenwood/cli/src/lib/resource-interface');
2222

23-
class ExampleResource extends ResourceInterface {
24-
constructor(compilation, options) {
25-
super(compilation, options);
26-
this.extensions = ['.foo'];
27-
this.contentType = 'text/javascript';
23+
class ResourceInterface {
24+
constructor(compilation, options = {}) {
25+
this.compilation = compilation;
26+
this.options = options;
27+
this.extensions = [];
28+
this.contentType = '';
2829
}
2930

30-
// test if this plugin should change a relative URL from the browser to an absolute path on disk (like for node_modules/)
31+
// test if this plugin should change a relative URL from the browser to an absolute path on disk
32+
// like for node_modules/ resolution. not commonly needed by most resource plugins
3133
// return true | false
32-
// eslint-disable-next-line no-unused-vars
3334
async shouldResolve(url) {
3435
return Promise.resolve(false);
3536
}
@@ -39,32 +40,32 @@ class ExampleResource extends ResourceInterface {
3940
return Promise.resolve(url);
4041
}
4142

42-
// test if this plugin should be used to process a given url / header combo the browser and retu
43+
// test if this plugin should be used to process a given url / header for the browser
4344
// ex: `<script type="module" src="index.ts">`
4445
// return true | false
4546
async shouldServe(url, headers) {
4647
return Promise.resolve(this.extensions.indexOf(path.extname(url)) >= 0);
4748
}
4849

49-
// return the new body and / or contentType, e.g. convert file.foo -> .js
50+
// return the new body and / or contentType, e.g. convert file.foo -> file.js
5051
async serve(url, headers) {
5152
return Promise.resolve({});
5253
}
5354

5455
// test if this plugin should return a new body for an already resolved resource
55-
// useful for modifying code on the fly without needing to touch the file
56+
// useful for modifying code on the fly without needing to read the file from disk
5657
// return true | false
5758
async shouldIntercept(url, body, headers) {
5859
return Promise.resolve(false);
5960
}
6061

6162
// return the new body
6263
async intercept(url, body, headers) {
63-
return Promise.resolve(body);
64+
return Promise.resolve({ body });
6465
}
6566

6667
// test if this plugin should manipulate any files prior to any final optmizations happening
67-
// ex: add a "banner" to all .js files with a timestamp of the build
68+
// ex: add a "banner" to all .js files with a timestamp of the build, or minifying files
6869
// return true | false
6970
async shouldOptimize(url, body) {
7071
return Promise.resolve(false);

www/pages/plugins/rollup.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
label: 'Rollup'
3+
menu: side
4+
title: 'Rollup'
5+
index: 3
6+
---
7+
8+
## Rollup
9+
10+
These plugins allow users to tap into the [Rollup](https://rollupjs.org/) configuration that Greenwood uses to build and optimize the static assets (JS / CSS) of your site when running the `build` command. Simply use the `provider` method to return an array of rollup plugins. Easy!
11+
12+
### Example
13+
Install your favorite rollup plugin(s), then create a simple object to provde those plugins.
14+
15+
```javascript
16+
const bannerRollup = require('rollup-plugin-banner');
17+
const packageJson = require('./package.json');
18+
19+
module.exports = (options = {}) => {
20+
const now = new Date().now();
21+
22+
return [{
23+
type: 'rollup',
24+
name: 'plugin-something-something',
25+
provider: () => [
26+
banner(`/* ${packageJson.name} v${packageJson.version} - built at ${now}. */`)
27+
]
28+
}];
29+
};
30+
```
31+
32+
> _You can click to see an [example of a rollup plugin](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-import-css), which requires a rollup plugin as part of enabling `import` syntax for CSS files._

0 commit comments

Comments
 (0)