Skip to content

Commit

Permalink
fix(docz-core): remove DataServer from production build
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 29, 2019
1 parent 8715129 commit b8770ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/docz-core/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const build = async (args: Arguments<any>) => {
dataServer.register([states.config(config), states.entries(entries, config)])

try {
await Entries.writeApp(config, true)
await Entries.writeApp(config, false)
await Entries.writeImports(await entries.get())
await dataServer.start()
await run('onPreBuild', config)
Expand Down
9 changes: 5 additions & 4 deletions core/docz-core/src/lib/Entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ const writeAppFiles = async (config: Config, dev: boolean): Promise<void> => {
const onPreRenders = props('onPreRender')
const onPostRenders = props('onPostRender')

const isProd = !dev
const root = await compiled(fromTemplates('root.tpl.js'), { minimize: false })
const js = await compiled(fromTemplates('index.tpl.js'), { minimize: false })
const websocketUrl = `ws://${config.websocketHost}:${config.websocketPort}`

const rawRootJs = root({
theme,
isProd: !dev,
isProd,
wrapper: config.wrapper,
websocketUrl,
})

const rawIndexJs = js({
onPreRenders,
onPostRenders,
isProd: !dev,
isProd,
})

await fs.remove(paths.rootJs)
Expand All @@ -58,9 +59,9 @@ const writeAppFiles = async (config: Config, dev: boolean): Promise<void> => {
export type EntryMap = Record<string, EntryObj>

export class Entries {
public static async writeApp(config: Config, dev?: boolean): Promise<void> {
public static async writeApp(config: Config, dev: boolean): Promise<void> {
await fs.ensureDir(paths.app)
await writeAppFiles(config, Boolean(dev))
await writeAppFiles(config, dev)
}

public static async writeImports(map: EntryMap): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions core/docz-core/templates/root.tpl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Link, Router, Routes<% if (isProd) {%>, useDataServer<%}%> } from 'docz'
import { Link, Router, Routes<% if (!isProd) {%>, useDataServer<%}%> } from 'docz'
<% if (!isProd) {%>import { hot } from 'react-hot-loader'<%}%>
import Theme from '<%- theme %>'

Expand All @@ -8,7 +8,7 @@ import database from './db.json'
<% if (wrapper) {%>import Wrapper from '<%- wrapper %>'<%}%>

const Root = () => {
<% if (websocketUrl || isProd) {%>useDataServer('<%- websocketUrl %>')<%}%>
<% if (!isProd && websocketUrl) {%>useDataServer('<%- websocketUrl %>')<%}%>
return (
<Theme
<% if (wrapper) {%>wrapper={Wrapper}<%}%>
Expand Down

0 comments on commit b8770ec

Please sign in to comment.