Skip to content

Commit

Permalink
Update Lerna, add more babel docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Oct 10, 2017
1 parent 09de938 commit 60e03dc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "2.2.0",
"lerna": "2.4.0",
"packages": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
},
"homepage": "https://diffhtml.org/",
"devDependencies": {
"lerna": "2.2.0"
"lerna": "2.4.0"
}
}
57 changes: 44 additions & 13 deletions packages/babel-plugin-transform-diffhtml/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# <±/> diffHTML Babel Transform Plugin

*Pre-compiles your tagged template strings to reduce runtime cost*
*Compiles your tagged template strings to Virtual Tree objects which reduces
runtime cost*

Stable Version: 1.0.0-beta.9

This plugin transforms tagged template strings `html` in your projects to
`createTree` calls. By default it will use `diff.createTree` which will need to
be imported into your module. This works out-of-the-box with the `diffhtml.js`
and `diffhtml-runtime.js` UMD script files.
This plugin transforms tagged template strings containing HTML to
JSX/HyperScript-like function calls. By default it will use `diff.createTree`
which will need to be imported into your module. This works out-of-the-box with
the `diffhtml.js` and `diffhtml-runtime.js` UMD script files.

## Installation

``` javascript
npm i --save-dev babel-plugin-transform-diffhtml
```

## Quick demo
## Simple example

Running:

Expand Down Expand Up @@ -47,13 +48,43 @@ class HelloWorld extends Component {
}
```

More specifically this plugin transforms tagged template strings
(`html`&lt;div&gt;&lt;/div&gt;``) in your JavaScript files to flat strings that
get parsed by the diffHTML HTML Parser. This ensures consistency with the
runtime parser. From there they are pieced back together using the AST into a
valid JSX/HyperScript-like `h(tagName, props, ...childNodes)`. This is both a
runtime performance optimization as well as a build time since you can exclude
more of diffHTML from your build.
## Recommend approach

A paved-path was designed to make authoring and optimizing markup easy. With
this approach you will not have typically JSX-like downsides, such as requiring
a build step, having to import a needless function like `React` or `h` (that
never gets used in your code).

To start, use ES modules (or CJS) to import the `html` tagged template helper:

``` js
import { html } from 'diffhtml';
```

Configure the babel plugin to find and replace with the same `html` value. The
runtime build which will be swapped in, automatically replaces the `html`
function with the `createTree` call. This saves you from needing to do a
needless import.

``` json
plugins: [
["transform-diffhtml", {
"tagName": "html",
"createTree": "html",
}]
]
```

## Additional details

More specifically this plugin transforms tagged template strings, like:
(`html`&lt;div&gt;&lt;/div&gt;``), in your JavaScript files to flat strings
that get parsed by the HTML parser in diffHTML core. The dynamic values get
replaced with string tokens. This ensures consistency with the runtime parser.
From there they are stitched back together using the AST into a valid
JSX/HyperScript-like `h(tagName, props, ...childNodes)`. This is both a runtime
performance optimization as well as a build time since you can exclude more of
diffHTML from your build.

**Note!* This plugin has been built for use in Babel 6.x environments, and will
not work with Babel 5.x ( *deprecated*) or older versions.**
Expand Down

0 comments on commit 60e03dc

Please sign in to comment.