Skip to content

Commit d1c3ad8

Browse files
Merge pull request #118 from remarkablemark/build/rollup
build: replace `webpack` with `rollup` in order to optimize bundle
2 parents 474c8cd + 00a4aad commit d1c3ad8

File tree

5 files changed

+40
-46
lines changed

5 files changed

+40
-46
lines changed

index.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ export interface HTMLReactParserOptions {
1515
}
1616

1717
/**
18-
* Convert HTML string to React elements.
18+
* Converts HTML string to React elements.
1919
*
20-
* @param - Raw string of HTML to parse.
21-
* @param options - Options to use when converting to react.
22-
* @returns ReactElement on successful parse or string when `html` cannot be
23-
* parsed as HTML
20+
* @param html - The HTML string to parse to React.
21+
* @param options - The parser options.
22+
* @return - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
2423
*/
2524
declare function HTMLReactParser(
2625
html: string,

index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ var htmlToDOM = require('html-dom-parser');
55
var domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false };
66

77
/**
8-
* Convert HTML string to React elements.
8+
* Converts HTML string to React elements.
99
*
10-
* @param {String} html - The HTML string.
11-
* @param {Object} [options] - The additional options.
10+
* @param {String} html - The HTML string to parse to React.
11+
* @param {Object} [options] - The parser options.
1212
* @param {Function} [options.replace] - The replace method.
13-
* @return {ReactElement|Array}
13+
* @return {ReactElement|Array|String} - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
1414
*/
1515
function HTMLReactParser(html, options) {
1616
if (typeof html !== 'string') {
@@ -19,10 +19,7 @@ function HTMLReactParser(html, options) {
1919
return domToReact(htmlToDOM(html, domParserOptions), options);
2020
}
2121

22-
/**
23-
* Export HTML to React parser.
24-
*/
25-
module.exports = HTMLReactParser;
22+
HTMLReactParser.domToReact = domToReact;
23+
HTMLReactParser.htmlToDOM = htmlToDOM;
2624

27-
module.exports.domToReact = domToReact;
28-
module.exports.htmlToDOM = htmlToDOM;
25+
module.exports = HTMLReactParser;

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"scripts": {
88
"benchmark": "node benchmark",
99
"build": "npm run clean && npm run build:min && npm run build:unmin",
10-
"build:min": "cross-env NODE_ENV=production webpack --output-filename html-react-parser.min.js",
11-
"build:unmin": "cross-env NODE_ENV=development webpack --output-filename html-react-parser.js",
10+
"build:min": "cross-env NODE_ENV=production rollup --config --file dist/html-react-parser.min.js --sourcemap",
11+
"build:unmin": "cross-env NODE_ENV=development rollup --config --file dist/html-react-parser.js",
1212
"clean": "rimraf dist",
1313
"coveralls": "nyc report --reporter=text-lcov | coveralls",
1414
"lint": "eslint --ignore-path .gitignore .",
@@ -58,9 +58,11 @@
5858
"react": "^16",
5959
"react-dom": "^16",
6060
"rimraf": "^2.6.3",
61-
"standard-version": "^6.0.1",
62-
"webpack": "^4.35.0",
63-
"webpack-cli": "^3.3.5"
61+
"rollup": "^1.16.2",
62+
"rollup-plugin-commonjs": "^10.0.0",
63+
"rollup-plugin-node-resolve": "^5.0.4",
64+
"rollup-plugin-uglify": "^6.0.2",
65+
"standard-version": "^6.0.1"
6466
},
6567
"peerDependencies": {
6668
"react": "^0.14 || ^15 || ^16"

rollup.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import commonjs from 'rollup-plugin-commonjs';
2+
import resolve from 'rollup-plugin-node-resolve';
3+
import { uglify } from 'rollup-plugin-uglify';
4+
5+
const config = {
6+
external: ['react'],
7+
input: 'index.js',
8+
output: {
9+
format: 'umd',
10+
globals: {
11+
react: 'React'
12+
},
13+
name: 'HTMLReactParser'
14+
},
15+
plugins: [commonjs(), resolve({ browser: true })]
16+
};
17+
18+
if (process.env.NODE_ENV === 'production') {
19+
config.plugins.push(uglify());
20+
}
21+
22+
export default config;

webpack.config.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)