File tree Expand file tree Collapse file tree 6 files changed +109
-0
lines changed
Expand file tree Collapse file tree 6 files changed +109
-0
lines changed Original file line number Diff line number Diff line change 1+ node_modules
2+ * .log
3+ package-lock.json
4+ dist
5+ build
Original file line number Diff line number Diff line change 1+ # preact-cli-plugin-async [ ![ npm] ( https://img.shields.io/npm/v/preact-cli-plugin-async.svg )] ( https://npm.im/preact-cli-plugin-async )
2+
3+ [ Preact CLI] plugin that adds optimized support for async/await via [ Kneden] .
4+
5+ ## Installation
6+
7+ ``` bash
8+ npm i -D preact-cli-plugin-async
9+ ```
10+
11+ ... then include it in your project by creating a ` preact.config.js ` :
12+
13+ ``` js
14+ import asyncPlugin from ' preact-cli-plugin-async' ;
15+
16+ export default (config ) => {
17+ asyncPlugin (config);
18+ }
19+ ```
20+
21+ ## License
22+
23+ MIT © [ developit] ( https://github.com/developit )
24+
25+ [ Kneden ] : https://github.com/babel/kneden
Original file line number Diff line number Diff line change 1+ export default function asyncPlugin ( config ) {
2+ let babel = config . module . loaders . filter ( loader => loader . loader === 'babel-loader' ) [ 0 ] . options ;
3+
4+ // Blacklist regenerator within env preset:
5+ babel . presets [ 0 ] [ 1 ] . exclude . push (
6+ 'transform-async-to-generator' ,
7+ 'transform-regenerator'
8+ ) ;
9+
10+ // Replace stage-1 preset with an inlined, flattened version without regenerator:
11+ babel . presets . pop ( ) ;
12+ babel . plugins . push (
13+ 'transform-export-extensions' ,
14+ 'syntax-dynamic-import' ,
15+ 'transform-class-properties' ,
16+ 'transform-object-rest-spread'
17+ ) ;
18+
19+ // Add Kneden
20+ babel . plugins . push ( require . resolve ( 'babel-plugin-async-to-promises' ) ) ;
21+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " preact-cli-plugin-async" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Preact CLI plugin that adds optimized support for async/await via Kneden." ,
5+ "main" : " dist/async-plugin.js" ,
6+ "source" : " async-plugin.js" ,
7+ "scripts" : {
8+ "build" : " microbundle" ,
9+ "test:build" : " ln -fs ../node_modules test && preact build --cwd test && bundlesize -f 'test/build/bundle.*.js' -s 4.5kB" ,
10+ "test" : " eslint async-plugin.js && npm run -s build && npm run -s test:build"
11+ },
12+ "eslintConfig" : {
13+ "extends" : " eslint-config-developit"
14+ },
15+ "keywords" : [
16+ " preact" ,
17+ " preact-cli" ,
18+ " preact cli plugin"
19+ ],
20+ "author" : " Jason Miller <jason@developit.ca> (http://jasonformat.com)" ,
21+ "license" : " MIT" ,
22+ "devDependencies" : {
23+ "bundlesize" : " ^0.15.3" ,
24+ "eslint" : " ^4.13.1" ,
25+ "eslint-config-developit" : " ^1.1.1" ,
26+ "microbundle" : " ^0.2.4" ,
27+ "preact-cli" : " ^2.1.0"
28+ },
29+ "dependencies" : {
30+ "babel-plugin-async-to-promises" : " ^1.0.5"
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ import { Component } from 'preact' ;
2+
3+ export default class Foo extends Component {
4+ async update ( ) {
5+ let source = await ( await fetch ( '/' ) ) . text ( ) ;
6+ this . setState ( { source } ) ;
7+ }
8+
9+ componentDidMount ( ) {
10+ this . update ( ) ;
11+ }
12+
13+ render ( { } , { source } ) {
14+ return (
15+ < div >
16+ < h2 > HTML Source:</ h2 >
17+ < pre > { source } </ pre >
18+ </ div >
19+ ) ;
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ import asyncPlugin from '..' ;
2+
3+ export default config => {
4+ asyncPlugin ( config ) ;
5+ } ;
You can’t perform that action at this time.
0 commit comments