+```ts[src/Child.ts]
+import type { Parent } from './Parent';
-👉 See the **Recommendations** section for [JSDoc typechecking](#JSDoc-typechecking) and more [TypeScript usage tricks](#Type-imports).
+export class Child {
+ name: string;
+ parent: Parent;
-
+ constructor(name: string, parent: Parent) {
+ this.name = name;
+ this.parent = parent;
+ }
+}
+```
+
+:::
## ENV variables
Many JavaScript modules uses process variables for both browser and Node environments. Expecially frameworks and web apps try to access the value of the `process.env.NODE_ENV` member in order to detect test or production environments. RNA comes with a plugin that automatically replaces the expression with the actual value.
```sh
-$ NODE_ENV='production' npx rna build src/index.js --output public/index.js
+NODE_ENV='production' npx rna build src/index.js --output public/index.js
```
-**Input**
+::: code-group
-```javascript
+```ts[src/index.js]
const response = await fetch('/data.json');
if (process.env.NODE_ENV !== 'production') {
console.log('DEBUG', response);
}
```
-**Output**
+:::
+
+::: code-group
-```javascript
+```ts[public/index.js]
const response = await fetch('/data.json');
```
+:::
+
The console statement will be removed because of dead code elimination.
## Assets
Generally, files are referenced in JavaScript scripts with non-standard inputs and ad hoc loaders:
-```javascript
+```ts
import IMAGE_URL from './assets/logo.png';
```
Since esbuild supports this common convention, RNA treats every unknown import as external file reference, delegating to esbuild assets collection and optimization.
-Accordingly to its [architecture](./Architecture), RNA encourages and supports for assets referenced by standard `URL` instances:
+Accordingly to its [architecture](./architecture), RNA encourages and supports for assets referenced by standard `URL` instances:
-```javascript
+```ts
const IMAGE_URL = new URL('./assets/logo.png', import.meta.url).href;
const response = await fetch(IMAGE_URL);
const blob = await response.blob();
@@ -268,50 +319,51 @@ This kind of reference is natively supported by browser and Node. During the bui
In a vary similar way, RNA collects builds `new Worker()` reference along the main build:
-```javascript
+```ts
const worker = new Worker('./path/to/worker.js');
```
Please note that RNA does not generate a `Worker` class to instantiate like webpack does, but it will just correctly update the import reference. If you need a `Worker` class, you have to wrap it yourself:
-```javascript
+```ts
const workerClass = function () {
return new Worker('./path/to/worker.js');
};
```
-⚠️ At the moment the Worker plugin does not collect `importScript()` statements and does treat workers as modules, but we have plan to support the `{ type: "module" }` option in the near future.
+::: warning
+
+At the moment the Worker plugin does not collect `importScript()` statements and does treat workers as modules, but we have plan to support the `{ type: "module" }` option in the near future.
+
+:::
## JSX
-Although JSX is not part of EcmaScript standards, it is largerly used by many projects and the benifits it brings are real, even if [you may not need it](#Tagged-templates).
Esbuild supports JSX transpilation, so RNA does it too. A plugin for auto importing the JSX pragma from a module is also available with the bundler.
```sh
-npx rna build src/index.js --output public/index.js --jsx automatic --jsxImportSource '@chialab/dna'
+rna build src/index.js --output public/index.js --jsx automatic --jsxImportSource '@chialab/dna'
```
-**Input**
+::: code-group
-```javascript
+```tsx[src/index.js]
import { render } from '@chialab/dna';
render(
-
-👉 See the **Recommendations** section for JSX alternatives using [Tagged Templates](#Tagged-templates).
-
-
+:::
## Targeting ES5
@@ -319,155 +371,20 @@ Even if modern JavaScript is supported by the majority of browsers, sometimes we
RNA provides a [Babel](https://babeljs.io/) plugin for this scopes. Once installed, it is automatically loaded by the RNA cli.
-```sh
+::: code-group
+
+```sh[npm]
npm i -D @chialab/esbuild-plugin-babel
```
-```sh
+```sh[yarn]
yarn add -D @chialab/esbuild-plugin-babel
```
-This will install Babel core packages, its [env preset](https://babeljs.io/docs/en/babel-preset-env) and an adapter for esbuild. You can configure the output using a [browserslist query](https://babeljs.io/docs/en/babel-preset-env#browserslist-integration) or specifying a Babel's [config file](https://babeljs.io/docs/en/config-files) in the root of your project.
-
----
-
-## Recommendations
-
-Here's a list of authors' reccomendations for your project setup. Some of those hints are out of the scope of RNA itself, but they are foundamental for JavaScript development.
-
-### Eslint
-
-Eslint is the most common linter for JavaScript. It is pluggable with parsers and custom rules and there is great community support.
-First, you need to install the eslint cli:
-
-```sh
-npm i -D eslint
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-babel
```
-Please follow official guide for [linter configuration](https://eslint.org/docs/user-guide/configuring/).
-
-We also provide our configuration preset:
-
-```sh
-npm i -D @chialab/eslint-config
-```
-
-**.eslintrc.json for JavaScript projects**
-
-```json
-{
- "extends": ["@chialab/eslint-config/javascript"]
-}
-```
-
-**.eslintrc.json for TypeScript projects**
-
-```json
-{
- "extends": ["@chialab/eslint-config/typescript"]
-}
-```
-
-Also, do not forget to install the linter extension for your IDE:
-
-- [VSCode](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
-
-### Tagged templates
-
-Template Strings came with ES2015. They can be used to interpolate texts but also to execute more complex string manipulation using a "tag":
-
-```js
-return tag`Hello ${name || 'world'}!`;
-```
-
-Since then, a lot of libraries, such as `lit-html` and `uhtml`, have been released to generate views using Tagged Templates.
-Tagged Templates are similar to JSX: they have typings support, colorized syntax, autocomplete, hints and more but they are 100% standard JavaScript, so they don't need a transpilation step before landing the browser.
-
-Furthermore, the [htm](https://github.com/developit/htm) module can be used to bring Tagged Templates support to those libraries that export the JSX pragma only:
-
-```js
-import htm from 'htm';
-import React from 'react';
-import ReactDOM from 'react-dom';
-
-const html = htm.bind(React.createElement);
-ReactDOM.render(html`Hello!`, document.body);
-```
-
-### JSDoc typechecking
-
-You don't need TypeScipt to typecheck JavaScript, or better to say, you can use the `typescript` module to check JavaScript syntax without using its syntax.
-Since version 4, TypeScript improved JSDoc support and its compiler can now check JavaScript sources as well as generate `.d.ts` declarations.
-
-**tsconfig.json**
-
-```json
-{
- "compilerOptions": {
- "allowJs": true,
- "checkJs": true
- },
- "include": ["src/**/*.ts", "src/**/*.js"]
-}
-```
-
-**index.ts**
-
-```typescript
-function sum(a: number, b: number) {
- return a + b;
-}
-```
+:::
-**index.js** (equivalent)
-
-```js
-/**
- * @param {number} a
- * @param {number} b
- */
-function sum(a, b) {
- return a + b;
-}
-```
-
-The pros of this solution is that you can skip the transpilation step if you are using standard JavaScript while still performing a typecheck, the cons are a more verbose syntax and the lack of TypeScript features such as decorators.
-
-### Type imports
-
-During the build step, esbuild removes type references and it is smart enough to detect side effects imports, but sometimes circular dependencies can cause imports order and dead code elimination issues.
-
-Since version 4, TypeScript introduced the `import type` statement that instructs the bundlers how a reference is used.
-It is recommended to use this feature to import interfaces, types and references used as type only.
-
-For example:
-
-**Parent.js**
-
-```typescript
-import { Child } from './Child';
-
-export class Parent {
- children: Child[] = [];
-
- addChild(name: string) {
- this.children.push(new Child(name, this));
- }
-}
-```
-
-**Child.js**
-
-```typescript
-import type { Parent } from './Parent';
-
-export class Child {
- name: string;
- parent: Parent;
-
- constructor(name: string, parent: Parent) {
- this.name = name;
- this.parent = parent;
- }
-}
-```
+This will install Babel core packages, its [env preset](https://babeljs.io/docs/en/babel-preset-env) and an adapter for esbuild. You can configure the output using a [browserslist query](https://babeljs.io/docs/en/babel-preset-env#browserslist-integration) or specifying a Babel's [config file](https://babeljs.io/docs/en/config-files) in the root of your project.
diff --git a/docs/Building-web-apps.md b/docs/guide/building-web-apps.md
similarity index 93%
rename from docs/Building-web-apps.md
rename to docs/guide/building-web-apps.md
index 7f520256..c03671ba 100644
--- a/docs/Building-web-apps.md
+++ b/docs/guide/building-web-apps.md
@@ -6,27 +6,43 @@ Esbuild supports out of the box bundling for JavaScript and CSS. RNA introduces
In order to bundle a Single Page Application using RNA you may have to install the bundler:
-```sh
+::: code-group
+
+```sh[npm]
npm i -D @chialab/rna
```
-```sh
+```sh[yarn]
yarn add -D @chialab/rna
```
+```sh[pnpm]
+pnpm add -D @chialab/rna
+```
+
+:::
+
and run:
-```sh
+::: code-group
+
+```sh[npm]
npx rna build src/index.html --output public
```
-```sh
+```sh[yarn]
yarn rna build src/index.html --output public
```
+```sh[pnpm]
+pnpx rna build src/index.html --output public
+```
+
+:::
+
## Collecting scripts
-Scripts are bundled following the conventions describe in the [Building JavaScript](./Building-javascript) page.
+Scripts are bundled following the conventions describe in the [Building JavaScript](./building-javascript) page.
There are two kinds of script: plain and module.
**Module scripts** can use ESM import/export statements and they are referenced in the HTML file using a script with `type="module"`. Source can be inline:
@@ -76,7 +92,7 @@ Plain scripts will output using `iife` format and `es5` target if the `@chialab/
## Collecting styles
-Styles can be imported as file using a `` or inlined using the `style` tag. Both will resolve `@import` statements and collect `url()` files, following the conventions describe in the [Building CSS](./Building-css) page.
+Styles can be imported as file using a `` or inlined using the `style` tag. Both will resolve `@import` statements and collect `url()` files, following the conventions describe in the [Building CSS](./building-css) page.
For example:
@@ -211,9 +227,9 @@ If the referenced manifest does not exists, RNA will start from a blank JSON fil
href="app.webmanifest" />
```
-**app.webmanifest**
+::: code-group
-```js
+```js[app.webmanifest]
{
name, //
description, //
@@ -227,3 +243,5 @@ If the referenced manifest does not exists, RNA will start from a blank JSON fil
icons, //
}
```
+
+:::
diff --git a/docs/Dev-server-web-apps.md b/docs/guide/dev-server.md
similarity index 87%
rename from docs/Dev-server-web-apps.md
rename to docs/guide/dev-server.md
index 9340f458..45e99166 100644
--- a/docs/Dev-server-web-apps.md
+++ b/docs/guide/dev-server.md
@@ -23,24 +23,40 @@ The [Web Dev Server](https://modern-web.dev/docs/dev-server/overview/) is a serv
The RNA dev server can be installed with the following preset:
-```sh
+::: code-group
+
+```sh[npm]
npm i -D @chialab/rna @chialab/rna-dev-server
```
-```sh
+```sh[yarn]
yarn add -D @chialab/rna @chialab/rna-dev-server
```
+```sh[pnpm]
+pnpm add -D @chialab/rna @chialab/rna-dev-server
+```
+
+:::
+
Run the dev server:
-```sh
+::: code-group
+
+```sh[npm]
npx rna serve src
```
-```sh
+```sh[yarn]
yarn rna serve src
```
+```sh[pnpm]
+pnpx rna serve src
+```
+
+:::
+
You can also specify a custom port using the `--port N` flag.
## Legacy browsers
@@ -48,21 +64,31 @@ You can also specify a custom port using the `--port N` flag.
Sometimes you may need to test on legacy browsers. Since the Dev Server is based on ESM support, in order to work in Internet Explorer or Safari 9 it needs to transpile and convert the module system.
Installing the [legacy plugin](https://www.npmjs.com/package/@chialab/wds-plugin-legacy) will enable the convertion of ESM modules to [SystemJS](https://github.com/systemjs/systemjs) and it will inject required polyfills for `Promise` and `fetch`.
-```sh
+::: code-group
+
+```sh[npm]
npm i -D @chialab/wds-plugin-legacy
```
-```sh
+```sh[yarn]
yarn add -D @chialab/wds-plugin-legacy
```
+```sh[pnpm]
+pnpm add -D @chialab/wds-plugin-legacy
+```
+
+:::
+
## Dev server as service
The Dev Server can be used as a service for other stacks. The `serve` command loads a RNA config object (using the `--config` flag or looking for `rna.config.js` file in the project) and reads the `entrypoints` option in order to generate a JSON files with all the required references.
For example, the following configuration:
-```ts
+::: code-group
+
+```ts[rna.config.js]
export default {
entrypoints: [{ input: 'webroot/index.js' }, { input: 'webroot/index.css' }],
format: 'esm',
@@ -70,17 +96,17 @@ export default {
};
```
-```sh
-npx rna serve --port 3000
-```
+:::
```sh
-yarn rna serve --port 3000
+rna serve --port 3000
```
will generate the **webroot/entrypoints.json** file with contents:
-```json
+::: code-group
+
+```json[webroot/entrypoints.json]
{
"index": {
"format": "esm",
@@ -90,6 +116,8 @@ will generate the **webroot/entrypoints.json** file with contents:
}
```
+:::
+
Then, you can read this file and load resources in your PHP application:
```twig
diff --git a/docs/guide/esbuild-plugin-any-file.md b/docs/guide/esbuild-plugin-any-file.md
new file mode 100644
index 00000000..8c255ff7
--- /dev/null
+++ b/docs/guide/esbuild-plugin-any-file.md
@@ -0,0 +1,34 @@
+# esbuild-plugin-any-file
+
+A loader plugin for [esbuild](https://esbuild.github.io/) for files with unknown loader.
+
+This plugins scans configured esbuild loaders. If it can't find a loader for an entrypoint, it will try to load it as a file.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-any-file
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-any-file
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-any-file
+```
+
+:::
+
+## Usage
+
+```ts
+import filePlugin from '@chialab/esbuild-plugin-any-file';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [filePlugin()],
+});
+```
diff --git a/docs/guide/esbuild-plugin-babel.md b/docs/guide/esbuild-plugin-babel.md
new file mode 100644
index 00000000..ab2c2dfb
--- /dev/null
+++ b/docs/guide/esbuild-plugin-babel.md
@@ -0,0 +1,42 @@
+# esbuild-plugin-babel
+
+An [esbuild](https://esbuild.github.io/) plugin that runs [babel](https://babeljs.io/) for es5 transpilation.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-babel
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-babel
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-babel
+```
+
+:::
+
+## Usage
+
+::: info
+
+If no configuration is provided, the plugin defaults already includes [typescript syntax support](https://babeljs.io/docs/en/babel-plugin-transform-typescript), the [env preset](https://babeljs.io/docs/en/babel-preset-env) and supports the [transpilation of tagged templates with htm](https://www.npmjs.com/package/babel-plugin-htm) to JSX.
+
+:::
+
+```ts
+import babelPlugin from '@chialab/esbuild-plugin-babel';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [
+ babelPlugin({
+ // babel config
+ }),
+ ],
+});
+```
diff --git a/docs/guide/esbuild-plugin-commonjs.md b/docs/guide/esbuild-plugin-commonjs.md
new file mode 100644
index 00000000..7a7a6c2d
--- /dev/null
+++ b/docs/guide/esbuild-plugin-commonjs.md
@@ -0,0 +1,40 @@
+# esbuild-plugin-commonjs
+
+A commonjs to esm converter for [esbuild](https://esbuild.github.io/).
+
+## Why
+
+When a dependency is loaded using `require` but marked as external, esbuild will not transform the require statement, breaking the ESM module.
+
+This plugin will transform the `require` statements to `import` statements, so that the module will be correctly loaded as ESM.
+
+Furthermore, even if UMD modules are transformed to ESM, they still will pollute the `window` singleton in browsers, in order to preserve dependencies injection.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-commonjs
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-commonjs
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-commonjs
+```
+
+:::
+
+## Usage
+
+```ts
+import commonjsPlugin from '@chialab/esbuild-plugin-commonjs';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [commonjsPlugin()],
+});
+```
diff --git a/docs/guide/esbuild-plugin-css-import.md b/docs/guide/esbuild-plugin-css-import.md
new file mode 100644
index 00000000..2091cc4f
--- /dev/null
+++ b/docs/guide/esbuild-plugin-css-import.md
@@ -0,0 +1,72 @@
+# esbuild-plugin-css-import
+
+Resolve CSS imports using the node resolution algorithm and the `style` field in package.json.
+
+## Why
+
+CSS modules resolution is not standardized, so it's not possible to natively import CSS files from node_modules using the `@import` statement.
+
+This plugin enables the node resolution algorithm for CSS files. That means that `@import` and `@url()` statements can refer to both relative files and NPM packages. CSS modules must have the `style` field in their package.json in order to correctly pickup the CSS entrypoint.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-css-import
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-css-import
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-css-import
+```
+
+:::
+
+## Usage
+
+```ts
+import cssImportPlugin from '@chialab/esbuild-plugin-css-import';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [cssImportPlugin()],
+});
+```
+
+### Example
+
+::: code-group
+
+```css[src/main.css]
+@import 'toggle';
+
+body {
+ color: var(--accent-color);
+}
+```
+
+```json[node_modules/toggle/package.json]
+{
+ "name": "toggle",
+ "main": "index.js",
+ "style": "index.css",
+ "exports": {
+ ".": {
+ "style": "./index.css",
+ "default": "./index.js"
+ }
+ }
+}
+```
+
+```css[node_modules/toggle/index.css]
+:root {
+ --accent-color: #000;
+}
+```
+
+:::
diff --git a/docs/guide/esbuild-plugin-env.md b/docs/guide/esbuild-plugin-env.md
new file mode 100644
index 00000000..9e7ab2d6
--- /dev/null
+++ b/docs/guide/esbuild-plugin-env.md
@@ -0,0 +1,34 @@
+# esbuild-plugin-env
+
+Define all environement variables for [esbuild](https://esbuild.github.io/).
+
+Replace `process.env.SOMETHING` occurences with the corresponding value, even for browser builds.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-env
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-env
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-env
+```
+
+:::
+
+## Usage
+
+```ts
+import envPlugin from '@chialab/esbuild-plugin-env';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [envPlugin()],
+});
+```
diff --git a/docs/guide/esbuild-plugin-html.md b/docs/guide/esbuild-plugin-html.md
new file mode 100644
index 00000000..ce5e1af0
--- /dev/null
+++ b/docs/guide/esbuild-plugin-html.md
@@ -0,0 +1,235 @@
+# esbuild-plugin-html
+
+A HTML loader plugin for [esbuild](https://esbuild.github.io/).
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-html
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-html
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-html
+```
+
+:::
+
+## Usage
+
+The plugin tries to respect esbuild configuration closely as possible. Since it treats HTML files as entrypoints, the resulting documents will use the pattern provided by `entryNames`, while JavaScript and CSS files will be written using the `chunkNames` config. Other files use the `assetNames` option.
+
+### Common configurations
+
+#### Build mode
+
+```js
+import htmlPlugin from '@chialab/esbuild-plugin-html';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ entryPoints: ['src/index.html'],
+ outdir: 'public',
+ assetNames: 'assets/[name]-[hash]',
+ chunkNames: '[ext]/[name]-[hash]',
+ plugins: [htmlPlugin()],
+});
+```
+
+The output structure would be something similar to:
+
+```
+public
+├── index.html
+├── assets/favicon-YYYYY.png
+├── css/style-YYYYY.css
+├── css/style-YYYYY.css.map
+├── js/index-YYYYY.js
+└── js/index-YYYYY.js.map
+```
+
+#### Serve mode
+
+```js
+import htmlPlugin from '@chialab/esbuild-plugin-html';
+import esbuild from 'esbuild';
+
+await esbuild.serve(
+ {
+ servedir: 'public',
+ },
+ {
+ entryPoints: ['src/index.html'],
+ outdir: 'public',
+ assetNames: 'assets/[name]',
+ chunkNames: '[ext]/[name]',
+ plugins: [htmlPlugin()],
+ }
+);
+```
+
+### Options
+
+The HTML plugin accepts an options object with the following properties:
+
+#### `scriptsTarget`
+
+The target of the plain scripts build (`type="text/javascript"`).
+
+#### `modulesTarget`
+
+The target of the ES modules build (`type="module"`).
+
+## How it works
+
+**Esbuild Plugin HTML** instructs esbuild to load a HTML file as entrypoint. It parses the HTML and runs esbuild on scripts, styles, assets and icons.
+
+### Scripts
+
+It handles both inline and file scripts. When the `type="module"` attribute is found in the `
+
+```
+
+This will result in producing two bundles:
+
+```html
+
+
+```
+
+### Styles
+
+It supports both `` and `
+```
+
+This will result in producing two css bundles:
+
+```html
+
+
+```
+
+### Assets
+
+Referenced files by `src` and `href` attributes are copy along the html file in the `assets` directory.
+
+**Sample**
+
+```html
+
+```
+
+This will result in:
+
+```html
+
+```
+
+### Icons
+
+Manually generate favicons can be a pain. This plugin detects a `` node and uses its reference to generate icons and launch screens for (almost) every browser.
+
+**Sample**
+
+```html
+
+```
+
+This will result in:
+
+```html
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+It also update `` content if found.
diff --git a/docs/guide/esbuild-plugin-meta-url.md b/docs/guide/esbuild-plugin-meta-url.md
new file mode 100644
index 00000000..24907a78
--- /dev/null
+++ b/docs/guide/esbuild-plugin-meta-url.md
@@ -0,0 +1,42 @@
+# esbuild-plugin-meta-url
+
+A file loader plugin for [esbuild](https://esbuild.github.io/) for constructed URLs using import metadata.
+
+The plugin looks for `new URL('path/to/file.png', import.meta.url)` in JavaScript and TypeScript files and instructs esbuild to copy referenced files. This is a standard version of the file loader.
+
+```js
+// DONT ❌
+import img from './logo.png';
+
+// DO ✅
+const img = new URL('./logo.png', import.meta.url).href;
+```
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-meta-url
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-meta-url
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-meta-url
+```
+
+:::
+
+## Usage
+
+```ts
+import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [metaUrlPlugin()],
+});
+```
diff --git a/docs/guide/esbuild-plugin-metadata.md b/docs/guide/esbuild-plugin-metadata.md
new file mode 100644
index 00000000..facb91c3
--- /dev/null
+++ b/docs/guide/esbuild-plugin-metadata.md
@@ -0,0 +1,70 @@
+# esbuild-plugin-metadata
+
+Write a entrypoints.json manifest for esbuild builds.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-metadata
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-metadata
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-metadata
+```
+
+:::
+
+## Usage
+
+```ts
+import metadataPlugin from '@chialab/esbuild-plugin-metadata';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [
+ metadataPlugin({
+ entrypoints: {
+ metafilePath: 'webroot/metafile.json',
+ manifestPath: 'webroot/manifest.json',
+ entrypointsPath: 'webroot/entrypoints.json',
+ },
+ }),
+ ],
+});
+```
+
+::: code-group
+
+```json[webroot/entrypoints.json]
+{
+ "index": {
+ "format": "esm",
+ "js": ["http://localhost:3000/__web-dev-server__web-socket.js", "http://localhost:3000/index.js"],
+ "css": ["http://localhost:3000/index.css"]
+ }
+}
+```
+
+:::
+
+Then, you can read this file and load resources in your PHP application:
+
+```twig
+{% set entrypoints = 'webroot/entrypoints.json'|file_get_content|json_decode %}
+{% for script in entrypoints.index.js %}
+
+{% endfor %}
+{% for link in entrypoints.index.css %}
+
+{% endfor %}
+```
+
+Here is a list of RNA-based helpers for common frameworks:
+
+- [RNA CakePHP](https://github.com/chialab/rna-cakephp)
diff --git a/docs/guide/esbuild-plugin-postcss.md b/docs/guide/esbuild-plugin-postcss.md
new file mode 100644
index 00000000..6a8df8ea
--- /dev/null
+++ b/docs/guide/esbuild-plugin-postcss.md
@@ -0,0 +1,54 @@
+# esbuild-plugin-postcss
+
+A CSS loader plugin for [esbuild](https://esbuild.github.io/) that uses [PostCSS](https://postcss.org/) as preprocessor.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-postcss
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-postcss
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-postcss
+```
+
+:::
+
+## Usage
+
+```js
+import postcssPlugin from '@chialab/esbuild-plugin-postcss';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [postcssPlugin()],
+});
+```
+
+This plugin looks for a postcss configuration in the project and fallbacks to out custom [postcss-preset-env](https://www.npmjs.com/package/postcss-preset-env).
+
+### Sass
+
+The plugin automatically tries to load the `@chialab/postcss-plugin-dart-sass` when it processes `.scss` files. Please make sure to have installed the optional dependency in order to correctly transpiler Sass files:
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/postcss-plugin-dart-sass
+```
+
+```sh[yarn]
+yarn add -D @chialab/postcss-plugin-dart-sass
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/postcss-plugin-dart-sass
+```
+
+:::
diff --git a/docs/guide/esbuild-plugin-require-resolve.md b/docs/guide/esbuild-plugin-require-resolve.md
new file mode 100644
index 00000000..81ab9fa8
--- /dev/null
+++ b/docs/guide/esbuild-plugin-require-resolve.md
@@ -0,0 +1,36 @@
+# esbuild-plugin-require-resolve
+
+A file loader plugin for [esbuild](https://esbuild.github.io/) for `require.resolve` statements.
+
+## How it works
+
+The plugin looks for `require.resolve('path/to/file.png')` statements in JavaScript and TypeScript files and instructs esbuild to copy referenced files.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-require-resolve
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-require-resolve
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-require-resolve
+```
+
+:::
+
+## Usage
+
+```ts
+import requireResolvePlugin from '@chialab/esbuild-plugin-require-resolve';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [requireResolvePlugin()],
+});
+```
diff --git a/docs/guide/esbuild-plugin-virtual.md b/docs/guide/esbuild-plugin-virtual.md
new file mode 100644
index 00000000..6a90358b
--- /dev/null
+++ b/docs/guide/esbuild-plugin-virtual.md
@@ -0,0 +1,51 @@
+# esbuild-plugin-virtual
+
+A virtual file system for [esbuild](https://esbuild.github.io/) modules.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-virtual
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-virtual
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-virtual
+```
+
+:::
+
+## Usage
+
+Define a virtual module:
+
+```ts
+import virtualPlugin from '@chialab/esbuild-plugin-virtual';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ entrypoints: ['index.js'],
+ plugins: [
+ virtualPlugin([
+ {
+ path: 'virtual-entry.js',
+ contents: 'export const nil = () => {};',
+ loader: 'js',
+ },
+ ]),
+ ],
+});
+```
+
+::: code-group
+
+```ts[index.js]
+import { nil } from 'virtual-entry.js';
+
+nil();
+```
diff --git a/docs/guide/esbuild-plugin-worker.md b/docs/guide/esbuild-plugin-worker.md
new file mode 100644
index 00000000..f5847624
--- /dev/null
+++ b/docs/guide/esbuild-plugin-worker.md
@@ -0,0 +1,70 @@
+# esbuild-plugin-worker
+
+Collect and transpile Web Workers with [esbuild](https://esbuild.github.io/).
+
+## How it works
+
+The plugin looks for `new Worker('./path/to/worker.js')` statements in JavaScript and TypeScript files and instructs esbuild to treat that references as entrypoints. Final output will be used to correctly update the statement.
+
+For example, the following script:
+
+```ts
+const worker = new Worker('./path/to/worker.js');
+```
+
+will be transformed to:
+
+```ts
+const worker = new Worker(new URL('./path/to/worker.js', import.meta.url));
+```
+
+and then resolved by the [`@chialab/esbuild-plugin-meta-url`](./esbuild-plugin-meta-url) plugin.
+
+Please note that RNA does not generate a `Worker` class to instantiate like webpack does, but it will just correctly update the import reference. If you need a `Worker` class, you have to wrap it yourself:
+
+```javascript
+const workerClass = function () {
+ return new Worker('./path/to/worker.js');
+};
+```
+
+::: warning
+
+At the moment this plugin does not collect `importScript()` statements and does treat workers as modules, but we have plan to support the `{ type: "module" }` option in the near future.
+
+:::
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/esbuild-plugin-worker
+```
+
+```sh[yarn]
+yarn add -D @chialab/esbuild-plugin-worker
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/esbuild-plugin-worker
+```
+
+:::
+
+## Usage
+
+```ts
+import workerPlugin from '@chialab/esbuild-plugin-worker';
+import esbuild from 'esbuild';
+
+await esbuild.build({
+ plugins: [workerPlugin()],
+});
+```
+
+You can also define a list of Worker constructors to use (default it will look for `Worker` and `SharedWorker`):
+
+```ts
+workerPlugin({ constructors: ['Worker', 'MyWorker'] });
+```
diff --git a/docs/Home.md b/docs/guide/index.md
similarity index 79%
rename from docs/Home.md
rename to docs/guide/index.md
index 071994a8..cfa411e9 100644
--- a/docs/Home.md
+++ b/docs/guide/index.md
@@ -1,18 +1,20 @@
+# Get started
+
## RNA is a bundler
RNA bundler is heavily based on [esbuild](https://esbuild.github.io/), _an extremely fast JavaScript bundler_ with some pre-configured addons. It can bundle and optimize JavaScript, TypeScript, JSX, CSS and HTML and collect referenced assets just using languages features.
The bundler is designed for modern browsers, but it can transpile code for IE11 and other legacy browsers with [Babel](https://babeljs.io/) and [PostCSS](https://postcss.org/) plugins.
-- [Build a JavaScript module](./Building-javascript)
-- [Build a CSS module](./Building-css)
-- [Build a Web App](./Building-web-apps)
+- [Build a JavaScript module](./building-javascript)
+- [Build a CSS module](./building-css)
+- [Build a Web App](./building-web-apps)
## RNA is a dev server
Build plugins are also available for the [Web Dev Server](https://modern-web.dev/docs/dev-server/overview/). Since both WDS and RNA aim to use standard syntax and practises in web projects, you can run a local server with hot module replacement and CSS livereload without have to bundle your web app first or to re-run a partial build for each change. Files loaded via ESM will pass through a little esbuild transpilation in order to support TypeScript, CommonJS modules and node resolution, making a great difference in developer experience. The dev server can be used also for PHP with an Encore-like approach.
-- [Dev server for web apps](./Dev-server-web-apps)
+- [Dev server for web apps](./dev-server)
## RNA is a browser and node test runner
@@ -20,32 +22,45 @@ Built on the Web Dev Server, a configured instance of the [Web Test Runner](http
Since RNA aims to support both browser and Node modules, you can test your modules in Node environments using the RNA test runner based on [Mocha](https://mochajs.org/). Coverage is also available thanks to the v8 coverage tool.
-- [Testing in the browser](./Testing-browser)
-- [Testing in node](./Testing-node)
-- [Testing in SauceLabs](./Testing-saucelabs)
+- [Testing in the browser](./testing-browser)
+- [Testing in node](./testing-node)
## RNA is a build framework
We built RNA to be pluggable and to be interoperable with other build systems. A lot of esbuild and postcss plugins are distribuited as standalone packages in order to be reused outside the RNA opinionated ecosystem. We also designed a micro-sdk for esbuild plugin authors that handles transform pipelines and emits chunks or files.
-- [Architecture](./Architecture)
-- [List of modules](./Plugins)
-- [Write a plugin](./Write-a-plugin)
-
## RNA is a cli
### Quick usage
-```sh
+::: code-group
+
+```sh[npm]
npm i -D \
@chialab/rna \
@chialab/rna-dev-server \
@chialab/rna-browser-test-runner
```
-**package.json**
+```sh[yarn]
+yarn add -D \
+ @chialab/rna \
+ @chialab/rna-dev-server \
+ @chialab/rna-browser-test-runner
+```
-```json
+```sh[pnpm]
+pnpm add -D \
+ @chialab/rna \
+ @chialab/rna-dev-server \
+ @chialab/rna-browser-test-runner
+```
+
+:::
+
+::: code-group
+
+```json[package.json]
{
"scripts": {
"start": "rna serve src --port 3000",
@@ -55,6 +70,4 @@ npm i -D \
}
```
-### Tutorials
-
-- [Migrate Create React App to RNA](./Migrate-CRA)
+:::
diff --git a/docs/Migrate-CRA.md b/docs/guide/migrate-CRA.md
similarity index 87%
rename from docs/Migrate-CRA.md
rename to docs/guide/migrate-CRA.md
index 46d840c5..80cad948 100644
--- a/docs/Migrate-CRA.md
+++ b/docs/guide/migrate-CRA.md
@@ -7,11 +7,23 @@ In this tutorial we will migrate [Create React App](https://facebook.github.io/c
The RNA dev server works serving a source directory that contains one (or more) HTML entrypoints. CRA static files are stored under the `public` folder, so we need to move them to the `src` directory:
```sh
-$ mv public/index.html src/index.html
-$ mv public/favicon.ico src/favicon.ico
-$ mv public/logo192.png src/logo192.png
-$ mv public/logo512.png src/logo512.png
-$ mv public/manifest.json src/manifest.json
+mv public/index.html src/index.html
+```
+
+```sh
+mv public/favicon.ico src/favicon.ico
+```
+
+```sh
+mv public/logo192.png src/logo192.png
+```
+
+```sh
+mv public/logo512.png src/logo512.png
+```
+
+```sh
+mv public/manifest.json src/manifest.json
```
### Replace `%PUBLIC_URL%` with local references
@@ -54,14 +66,22 @@ Optionally, you can also include a bundle for browsers that don't support ESM mo
First, we need to install `rna` dependencies:
-```sh
+::: code-group
+
+```sh[npm]
npm i -D @chialab/rna @chialab/rna-dev-server
```
-```sh
+```sh[yarn]
yarn add -D @chialab/rna @chialab/rna-dev-server
```
+```sh[pnpm]
+pnpm add -D @chialab/rna @chialab/rna-dev-server
+```
+
+:::
+
Then, we are ready to update the `package.json` file to replace `react-scripts` witn `rna`.
We will pass `--jsxImportSource` to make sure `React` JSX pragma is imported in JavaScript files. Other JSX configurations for React are automatically loaded by `esbuild`.
diff --git a/docs/guide/postcss-dart-sass.md b/docs/guide/postcss-dart-sass.md
new file mode 100644
index 00000000..bb952428
--- /dev/null
+++ b/docs/guide/postcss-dart-sass.md
@@ -0,0 +1,27 @@
+# postcss-dart-sass
+
+A [PostCSS](https://postcss.org/) plugin that uses dart [sass](https://sass-lang.com/) to transpile scss files.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/postcss-dart-sass
+```
+
+```sh[yarn]
+yarn add -D @chialab/postcss-dart-sass
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/postcss-dart-sass
+```
+
+:::
+
+## Usage
+
+```ts
+import '@chialab/postcss-dart-sass';
+```
diff --git a/docs/guide/postcss-url-rebase.md b/docs/guide/postcss-url-rebase.md
new file mode 100644
index 00000000..e2d17a2d
--- /dev/null
+++ b/docs/guide/postcss-url-rebase.md
@@ -0,0 +1,32 @@
+# postcss-url-rebase
+
+A [PostCSS](https://postcss.org/) plugin for `url()` rebasing before import.
+
+## Install
+
+::: code-group
+
+```sh[npm]
+npm i -D @chialab/postcss-url-rebase
+```
+
+```sh[yarn]
+yarn add -D @chialab/postcss-url-rebase
+```
+
+```sh[pnpm]
+pnpm add -D @chialab/postcss-url-rebase
+```
+
+:::
+
+## Usage
+
+```ts
+import postcss from 'postcss';
+import urlRebase from '@chialab/postcss-url-rebase';
+
+postcss([
+ urlRebase(),
+]).process(...);
+```
diff --git a/docs/Testing-browser.md b/docs/guide/testing-browser.md
similarity index 80%
rename from docs/Testing-browser.md
rename to docs/guide/testing-browser.md
index f0513680..021a5ed7 100644
--- a/docs/Testing-browser.md
+++ b/docs/guide/testing-browser.md
@@ -1 +1,3 @@
# Testing in the browser
+
+TODO
diff --git a/docs/Testing-node.md b/docs/guide/testing-node.md
similarity index 75%
rename from docs/Testing-node.md
rename to docs/guide/testing-node.md
index 15fb63f1..ea666c3c 100644
--- a/docs/Testing-node.md
+++ b/docs/guide/testing-node.md
@@ -1 +1,3 @@
# Testing in Node
+
+TODO
diff --git a/docs/Write-a-plugin.md b/docs/guide/write-a-plugin.md
similarity index 100%
rename from docs/Write-a-plugin.md
rename to docs/guide/write-a-plugin.md
diff --git a/docs/index.md b/docs/index.md
new file mode 100644
index 00000000..4f57ce5c
--- /dev/null
+++ b/docs/index.md
@@ -0,0 +1,26 @@
+---
+# https://vitepress.dev/reference/default-theme-home-page
+layout: home
+
+title: RNA
+titleTemplate: Build tools for modern web modules and applications
+
+hero:
+ name: 'RNA'
+ tagline: 'Build tools for modern web modules and applications'
+ image:
+ src: https://raw.githubusercontent.com/chialab/rna/main/logo.svg
+ alt: RNA logo
+ actions:
+ - theme: brand
+ text: npm i -D @chialab/rna
+ link: /guide/
+
+features:
+ - title: Modular
+ details: RNA is an ecosystem of modular plugins for common bundlers and transformers like esbuild and postcss. Every feature is a standalone package that can be installed and used independently.
+ icon:
+ - title: A toolchain
+ details: RNA is a toolchain for common frontend (and JavaScript in general) tasks with a strong conventions over configuration and largely opinionated policy.
+ icon:
+---
diff --git a/package.json b/package.json
index 66004d64..76efd77d 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,9 @@
"lint": "prettier --check . && eslint 'packages/*/lib/**/*.js'",
"test": "rna test:node packages/*/test/**/*.spec.js --coverage",
"new": "plop --plopfile internals/generators/plopfile.cjs module",
+ "docs:dev": "vitepress dev docs",
+ "docs:build": "vitepress build docs",
+ "docs:preview": "vitepress preview docs",
"version": "changeset version && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install"
},
"repository": {
diff --git a/packages/esbuild-plugin-any-file/README.md b/packages/esbuild-plugin-any-file/README.md
index 9abffeec..10fe7a31 100644
--- a/packages/esbuild-plugin-any-file/README.md
+++ b/packages/esbuild-plugin-any-file/README.md
@@ -6,30 +6,9 @@
----
+## Documentation
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-any-file -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-any-file -D
-```
-
-## Usage
-
-```js
-import filePlugin from '@chialab/esbuild-plugin-any-file';
-import esbuild from 'esbuild';
-
-await esbuild.build({
- plugins: [filePlugin()],
-});
-```
-
----
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-any-file).
## License
diff --git a/packages/esbuild-plugin-babel/README.md b/packages/esbuild-plugin-babel/README.md
index afbf069d..e4b3391a 100644
--- a/packages/esbuild-plugin-babel/README.md
+++ b/packages/esbuild-plugin-babel/README.md
@@ -1,39 +1,14 @@
- Esbuild Plugin Babel • A pluggable esbuild plugin that runs babel for es5 transpilation.
+ Esbuild Plugin Babel • An esbuild plugin that runs babel for es5 transpilation.
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-babel -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-babel -D
-```
-
-## Usage
-
-```js
-import esbuild from 'esbuild';
-import babelPlugin from '@chialab/esbuild-plugin-babel';
-
-await esbuild.build({
- plugins: [
- babelPlugin({
- plugins: [...],
- }),
- ],
-});
-```
+## Documentation
-Please not that it already includes [typescript syntax support](https://babeljs.io/docs/en/babel-plugin-transform-typescript), the [env preset](https://babeljs.io/docs/en/babel-preset-env) and supports the [transpilation of tagged templates with htm](https://www.npmjs.com/package/babel-plugin-htm) to JSX.
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-babel).
---
diff --git a/packages/esbuild-plugin-babel/package.json b/packages/esbuild-plugin-babel/package.json
index 0ee52520..eb1a5edc 100644
--- a/packages/esbuild-plugin-babel/package.json
+++ b/packages/esbuild-plugin-babel/package.json
@@ -2,7 +2,7 @@
"name": "@chialab/esbuild-plugin-babel",
"type": "module",
"version": "0.18.0",
- "description": "A pluggable esbuild plugin that runs babel for es5 transpilation.",
+ "description": "An esbuild plugin that runs babel for es5 transpilation.",
"main": "lib/index.js",
"typings": "./types/index.d.ts",
"author": "Chialab (https://www.chialab.it)",
diff --git a/packages/esbuild-plugin-commonjs/README.md b/packages/esbuild-plugin-commonjs/README.md
index 79d994c0..f1caa05f 100644
--- a/packages/esbuild-plugin-commonjs/README.md
+++ b/packages/esbuild-plugin-commonjs/README.md
@@ -6,28 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-commonjs -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-commonjs -D
-```
-
-## Usage
-
-```js
-import commonjsPlugin from '@chialab/esbuild-plugin-commonjs';
-import esbuild from 'esbuild';
+## Documentation
-await esbuild.build({
- plugins: [commonjsPlugin()],
-});
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-commonjs).
---
diff --git a/packages/esbuild-plugin-css-import/README.md b/packages/esbuild-plugin-css-import/README.md
index e178c6d1..e3c4ac5a 100644
--- a/packages/esbuild-plugin-css-import/README.md
+++ b/packages/esbuild-plugin-css-import/README.md
@@ -6,59 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-css-import -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-css-import -D
-```
-
-## Usage
-
-This plugin enables the node resolution algorithm for CSS files. That means that `@import` and `@url()` statements can refer to both relative files and NPM packages. CSS modules must have the `style` field in their pakcage.json in order to correctly pickup the CSS entrypoint.
-
-```js
-import cssImportPlugin from '@chialab/esbuild-plugin-css-import';
-import esbuild from 'esbuild';
-
-await esbuild.build({
- plugins: [cssImportPlugin()],
-});
-```
-
-### Example
-
-**node_modules/css-framework/package.json**
-
-```json
-{
- "name": "css-framework",
- "style": "index.css"
-}
-```
-
-**node_modules/css-framework/index.css**
-
-```css
-:root {
- --accent-color: #000;
-}
-```
-
-**src/main.css**
-
-```css
-@import 'css-framework';
+## Documentation
-body {
- color: var(--accent-color);
-}
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-css-import).
---
diff --git a/packages/esbuild-plugin-env/README.md b/packages/esbuild-plugin-env/README.md
index 933c8fe6..36222f18 100644
--- a/packages/esbuild-plugin-env/README.md
+++ b/packages/esbuild-plugin-env/README.md
@@ -6,28 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-env -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-env -D
-```
-
-## Usage
-
-```js
-import envPlugin from '@chialab/esbuild-plugin-env';
-import esbuild from 'esbuild';
+## Documentation
-await esbuild.build({
- plugins: [envPlugin()],
-});
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-env).
---
diff --git a/packages/esbuild-plugin-html/README.md b/packages/esbuild-plugin-html/README.md
index 07115df3..a70bfb8e 100644
--- a/packages/esbuild-plugin-html/README.md
+++ b/packages/esbuild-plugin-html/README.md
@@ -6,233 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-html -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-html -D
-```
-
-## Usage
-
-The plugin tries to respect esbuild configuration closely as possible. Since it treats HTML files as entrypoints, the resulting documents will use the pattern provided by `entryNames`, while JavaScript and CSS files will be written using the `chunkNames` config. Other files use the `assetNames` option.
-
-### Common configurations
-
-#### Build mode
-
-```js
-import htmlPlugin from '@chialab/esbuild-plugin-html';
-import esbuild from 'esbuild';
-
-await esbuild.build({
- entryPoints: ['src/index.html'],
- outdir: 'public',
- assetNames: 'assets/[name]-[hash]',
- chunkNames: '[ext]/[name]-[hash]',
- plugins: [htmlPlugin()],
-});
-```
-
-The output structure would be something similar to:
-
-```
-public
-├── index.html
-├── assets/favicon-YYYYY.png
-├── css/style-YYYYY.css
-├── css/style-YYYYY.css.map
-├── js/index-YYYYY.js
-└── js/index-YYYYY.js.map
-```
-
-#### Serve mode
-
-```js
-import htmlPlugin from '@chialab/esbuild-plugin-html';
-import esbuild from 'esbuild';
-
-await esbuild.serve(
- {
- servedir: 'public',
- },
- {
- entryPoints: ['src/index.html'],
- outdir: 'public',
- assetNames: 'assets/[name]',
- chunkNames: '[ext]/[name]',
- plugins: [htmlPlugin()],
- }
-);
-```
-
-### Options
-
-The HTML plugin accepts an options object with the following properties:
-
-#### `scriptsTarget`
-
-The target of the plain scripts build (`type="text/javascript"`).
-
-#### `modulesTarget`
-
-The target of the ES modules build (`type="module"`).
-
----
-
-## How it works
-
-**Esbuild Plugin HTML** instructs esbuild to load a HTML file as entrypoint. It parses the HTML and runs esbuild on scripts, styles, assets and icons.
-
-### Scripts
-
-It handles both inline and file scripts. When the `type="module"` attribute is found in the `
-
-```
-
-This will result in producing two bundles:
-
-```html
-
-
-```
-
-### Styles
-
-It supports both `` and `
-```
-
-This will result in producing two css bundles:
-
-```html
-
-
-```
-
-### Assets
-
-Referenced files by `src` and `href` attributes are copy along the html file in the `assets` directory.
-
-**Sample**
-
-```html
-
-```
-
-This will result in:
-
-```html
-
-```
-
-### Icons
-
-Manually generate favicons can be a pain. This plugin detects a `` node and uses its reference to generate icons and launch screens for (almost) every browser.
-
-**Sample**
-
-```html
-
-```
-
-This will result in:
-
-```html
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-```
+## Documentation
-It also update `` content if found.
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-html).
---
diff --git a/packages/esbuild-plugin-meta-url/README.md b/packages/esbuild-plugin-meta-url/README.md
index 08f709f0..39813a6c 100644
--- a/packages/esbuild-plugin-meta-url/README.md
+++ b/packages/esbuild-plugin-meta-url/README.md
@@ -6,42 +6,9 @@
----
-
-## How it works
-
-**Esbuild Plugin Meta Url** looks for `new URL('path/to/file.png', import.meta.url)` in JavaScript and TypeScript files and instructs esbuild to copy referenced files. This is a standard version of the file loader.
-
-```js
-// DONT ❌
-import img from './logo.png';
-
-// DO ✅
-const img = new URL('./logo.png', import.meta.url).href;
-```
-
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-meta-url -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-meta-url -D
-```
-
-## Usage
-
-```js
-import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';
-import esbuild from 'esbuild';
+## Documentation
-await esbuild.build({
- plugins: [metaUrlPlugin()],
-});
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-meta-url).
---
diff --git a/packages/esbuild-plugin-metadata/README.md b/packages/esbuild-plugin-metadata/README.md
index a7065a14..d9029c89 100644
--- a/packages/esbuild-plugin-metadata/README.md
+++ b/packages/esbuild-plugin-metadata/README.md
@@ -1,41 +1,14 @@
- esbuild-plugin-metadata • Write entrypoints.json for esbuild builds.
+ esbuild-plugin-metadata • Write entrypoints.json manifest for esbuild builds.
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-metadata -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-metadata -D
-```
-
-## Usage
-
-```js
-import metadataPlugin from '@chialab/esbuild-plugin-metadata';
-import esbuild from 'esbuild';
+## Documentation
-await esbuild.build({
- plugins: [
- metadataPlugin({
- entrypoints: {
- metafilePath: 'build/metafile.json',
- manifestPath: 'build/manifest.json',
- entrypointsPath: 'build/entrypoints.json',
- },
- }),
- ],
-});
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-metadata).
---
diff --git a/packages/esbuild-plugin-postcss/README.md b/packages/esbuild-plugin-postcss/README.md
index 30bcdc79..60d144fc 100644
--- a/packages/esbuild-plugin-postcss/README.md
+++ b/packages/esbuild-plugin-postcss/README.md
@@ -6,42 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-postcss -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-postcss -D
-```
-
-## Usage
-
-```js
-import postcssPlugin from '@chialab/esbuild-plugin-postcss';
-import esbuild from 'esbuild';
-
-await esbuild.build({
- plugins: [postcssPlugin()],
-});
-```
-
-This plugin looks for a postcss configuration in the project and fallbacks to out custom [postcss-preset-env](https://www.npmjs.com/package/postcss-preset-env).
-
-### Sass
-
-The plugin automatically tries to load the `@chialab/postcss-plugin-dart-sass` when it processes `.scss` files. Please make sure to have installed the optional dependency in order to correctly transpiler Sass files:
-
-```sh
-npm i @chialab/postcss-plugin-dart-sass -D
-```
+## Documentation
-```sh
-yarn add @chialab/postcss-plugin-dart-sass -D
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-postcss).
---
diff --git a/packages/esbuild-plugin-virtual/README.md b/packages/esbuild-plugin-virtual/README.md
index 15f20be3..6cf2f64f 100644
--- a/packages/esbuild-plugin-virtual/README.md
+++ b/packages/esbuild-plugin-virtual/README.md
@@ -6,47 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-virtual -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-virtual -D
-```
-
-## Usage
-
-Define a virtual module:
-
-```js
-import virtualPlugin from '@chialab/esbuild-plugin-virtual';
-import esbuild from 'esbuild';
-
-await esbuild.build({
- entrypoints: ['index.js'],
- plugins: [
- virtualPlugin([
- {
- path: 'virtual-entry.js',
- contents: 'export const nil = () => {};',
- loader: 'js',
- },
- ]),
- ],
-});
-```
-
-**index.js**
-
-```js
-import { nil } from 'virtual-entry.js';
+## Documentation
-nil();
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-virtual).
---
diff --git a/packages/esbuild-plugin-worker/README.md b/packages/esbuild-plugin-worker/README.md
index 140e6437..f61d6afa 100644
--- a/packages/esbuild-plugin-worker/README.md
+++ b/packages/esbuild-plugin-worker/README.md
@@ -6,65 +6,9 @@
----
-
-## How it works
-
-**Esbuild Plugin Worker** looks for `new Worker('./path/to/worker.js')` statements in JavaScript and TypeScript files and instructs esbuild to treat that references as entrypoints. Final output will be used to correctly update the statement.
-
-For example, the following script:
-
-```js
-const worker = new Worker('./path/to/worker.js');
-```
-
-will be transformed to:
-
-```js
-const worker = new Worker(new URL('./path/to/worker.js', import.meta.url));
-```
-
-and then resolved by the [`@chialab/esbuild-plugin-meta-url`](../esbuild-plugin-meta-url) plugin.
-
-Please note that RNA does not generate a `Worker` class to instantiate like webpack does, but it will just correctly update the import reference. If you need a `Worker` class, you have to wrap it yourself:
-
-```javascript
-const workerClass = function () {
- return new Worker('./path/to/worker.js');
-};
-```
-
-⚠️ At the moment this plugin does not collect `importScript()` statements and does treat workers as modules, but we have plan to support the `{ type: "module" }` option in the near future.
-
----
-
-## Install
-
-```sh
-npm i @chialab/esbuild-plugin-worker -D
-```
-
-```sh
-yarn add @chialab/esbuild-plugin-worker -D
-```
-
-## Usage
-
-```js
-import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';
-import workerPlugin from '@chialab/esbuild-plugin-worker';
-import esbuild from 'esbuild';
-
-await esbuild.build({
- plugins: [workerPlugin(), metaUrlPlugin()],
-});
-```
-
-You can also define a list of Worker constructors to use (default it will look for `Worker` and `SharedWorker`):
+## Documentation
-```js
-workerPlugin({ constructors: ['Worker', 'MyWorker'] });
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/esbuild-plugin-worker).
---
diff --git a/packages/postcss-dart-sass/README.md b/packages/postcss-dart-sass/README.md
index 1653a282..640ab148 100644
--- a/packages/postcss-dart-sass/README.md
+++ b/packages/postcss-dart-sass/README.md
@@ -6,23 +6,9 @@
----
-
-## Install
-
-```sh
-npm i @chialab/postcss-dart-sass -D
-```
-
-```sh
-yarn add @chialab/postcss-dart-sass -D
-```
-
-## Usage
+## Documentation
-```js
-import '@chialab/postcss-dart-sass';
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/postcss-dart-sass).
---
diff --git a/packages/postcss-url-rebase/README.md b/packages/postcss-url-rebase/README.md
index cc53239c..e3a05110 100644
--- a/packages/postcss-url-rebase/README.md
+++ b/packages/postcss-url-rebase/README.md
@@ -6,26 +6,9 @@
-## Install
+## Documentation
-```sh
-npm i @chialab/postcss-url-rebase -D
-```
-
-```sh
-yarn add @chialab/postcss-url-rebase -D
-```
-
-## Usage
-
-```js
-import postcss from 'postcss';
-import urlRebase from '@chialab/postcss-url-rebase';
-
-postcss([
- urlRebase(),
-]).process(...);
-```
+Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/postcss-url-rebase).
---