Skip to content

Commit 85b0da9

Browse files
authored
Merge pull request #69 from developit/react-integration
Add React integration
2 parents a487dda + 9b281f7 commit 85b0da9

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
package-lock.json
33
/preact
4+
/react
45
dist
56
mini
67
yarn.lock

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"umd:main": "dist/htm.umd.js",
77
"module": "dist/htm.mjs",
88
"scripts": {
9-
"build": "npm run -s build:main && npm run -s build:mini && npm run -s build:preact && npm run -s build:babel && npm run -s build:babel-transform-jsx",
9+
"build": "npm run -s build:main && npm run -s build:mini && npm run -s build:preact && npm run -s build:react && npm run -s build:babel && npm run -s build:babel-transform-jsx",
1010
"build:main": "microbundle src/index.mjs -f es,umd --no-sourcemap --target web && microbundle src/cjs.mjs -f iife --no-sourcemap --target web",
1111
"build:mini": "microbundle src/index.mjs -o ./mini/index.js -f es,umd --no-sourcemap --target web --alias ./constants=./constants-mini && microbundle src/cjs.mjs -o ./mini/index.js -f iife --no-sourcemap --target web --alias ./constants=./constants-mini",
1212
"build:preact": "cd src/integrations/preact && npm run build",
13+
"build:react": "cd src/integrations/react && npm run build",
1314
"build:babel": "cd packages/babel-plugin-htm && npm run build",
1415
"build:babel-transform-jsx": "cd packages/babel-plugin-transform-jsx-to-htm && npm run build",
1516
"test": "eslint src/**/*.mjs test/**/*.mjs && npm run build && jest test",
@@ -74,7 +75,8 @@
7475
"eslint-config-developit": "^1.1.1",
7576
"jest": "^24.1.0",
7677
"microbundle": "^0.10.1",
77-
"preact": "^8.4.2"
78+
"preact": "^8.4.2",
79+
"react": "^16.8.3"
7880
},
7981
"dependencies": {},
8082
"peerDependencies": {

src/integrations/react/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as React from 'react';
2+
declare const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement;

src/integrations/react/index.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
import { createElement } from 'react';
15+
import htm from 'htm';
16+
export const html = htm.bind(createElement);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "htm_react",
3+
"module": "index.mjs",
4+
"main": "index.js",
5+
"umd:main": "index.js",
6+
"unpkg": "index.js",
7+
"scripts": {
8+
"build": "npm run -s build:main && npm run -s build:static",
9+
"build:main": "microbundle index.mjs -o ../../../react/index.js -f es,umd --external react,htm --no-sourcemap --target web",
10+
"build:static": "cp index.d.ts package.json ../../../react/"
11+
}
12+
}

0 commit comments

Comments
 (0)