diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-05 21:07:31 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-05 21:07:31 +0200 |
commit | ee35da4be577943734d57c8c54a5c37f0cc10a0e (patch) | |
tree | 0df675523029fc4900929befc7449f2a2be86944 | |
parent | 24c4f419450487a8f52ec963e2f7b7de1c502e82 (diff) | |
download | gitbook-ee35da4be577943734d57c8c54a5c37f0cc10a0e.zip gitbook-ee35da4be577943734d57c8c54a5c37f0cc10a0e.tar.gz gitbook-ee35da4be577943734d57c8c54a5c37f0cc10a0e.tar.bz2 |
Add task to build gitbook.core.min.js
-rw-r--r-- | packages/gitbook-core/.gitignore | 1 | ||||
-rw-r--r-- | packages/gitbook-core/.npmignore | 1 | ||||
-rw-r--r-- | packages/gitbook-core/package.json | 10 | ||||
-rw-r--r-- | packages/gitbook/src/output/website/render.js | 22 |
4 files changed, 25 insertions, 9 deletions
diff --git a/packages/gitbook-core/.gitignore b/packages/gitbook-core/.gitignore new file mode 100644 index 0000000..1c25790 --- /dev/null +++ b/packages/gitbook-core/.gitignore @@ -0,0 +1 @@ +gitbook.core.js.min diff --git a/packages/gitbook-core/.npmignore b/packages/gitbook-core/.npmignore index e04684f..a128ba4 100644 --- a/packages/gitbook-core/.npmignore +++ b/packages/gitbook-core/.npmignore @@ -1,2 +1,3 @@ src !lib +!gitbook.core.js.min diff --git a/packages/gitbook-core/package.json b/packages/gitbook-core/package.json index 048a5c4..071837b 100644 --- a/packages/gitbook-core/package.json +++ b/packages/gitbook-core/package.json @@ -16,11 +16,15 @@ "babel-cli": "^6.14.0", "babel-preset-es2015": "^6.14.0", "babel-preset-react": "^6.11.1", - "babel-preset-stage-2": "^6.13.0" + "babel-preset-stage-2": "^6.13.0", + "browserify": "^13.1.0", + "envify": "^3.4.1", + "uglify-js": "^2.7.3" }, "scripts": { - "dist": "rm -rf lib/ && babel -d lib/ src/", - "prepublish": "npm run dist" + "dist-lib": "rm -rf lib/ && babel -d lib/ src/", + "dist-standalone": "browserify -r react -r react-dom -r ./lib/index.js:gitbook-core | uglifyjs -c > gitbook.core.js.min", + "prepublish": "npm run dist-lib && npm run dist-standalone" }, "repository": { "type": "git", diff --git a/packages/gitbook/src/output/website/render.js b/packages/gitbook/src/output/website/render.js index 8662305..237c234 100644 --- a/packages/gitbook/src/output/website/render.js +++ b/packages/gitbook/src/output/website/render.js @@ -2,8 +2,9 @@ const React = require('react'); const ReactDOMServer = require('react-dom/server'); const GitBook = require('gitbook-core'); -function HTML({head, innerHTML}) { +function HTML({head, innerHTML, props}) { const attrs = head.htmlAttributes.toComponent(); + const propsJSON = JSON.stringify(props); return ( <html {...attrs}> @@ -13,7 +14,11 @@ function HTML({head, innerHTML}) { {head.link.toComponent()} </head> <body> - <div id="content" dangerouslySetInnerHTML={{__html: innerHTML}} /> + <div id="content" dangerouslySetInnerHTML={{__html: innerHTML}} /> + {head.link.toComponent()} + <script + type="application/payload+json" + dangerouslySetInnerHTML={{__html: propsJSON}} /> </body> </html> ); @@ -31,12 +36,17 @@ HTML.propTypes = { function render(initialState) { const plugins = []; const store = GitBook.createStore(plugins, initialState); - const { el, head } = GitBook.renderComponent(store, { - role: 'Body' - }); + const { el, head } = GitBook.renderComponent(store, { role: 'Body' }); + // Render inner body const innerHTML = ReactDOMServer.renderToString(el); - const htmlEl = <HTML head={head} innerHTML={innerHTML} />; + + // Render whole HTML page + const htmlEl = <HTML + head={head} + innerHTML={innerHTML} + props={initialState} + />; const html = ReactDOMServer.renderToStaticMarkup(htmlEl); return html; |