Skip to content

Commit

Permalink
fix: ykfe-utils 依赖移除rax
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Mar 19, 2020
1 parent c60814f commit 0a494c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example/ssr-with-rax/web/entry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createElement, render } from 'rax' // eslint-disable-line
import { useRouter } from 'rax-use-router'
import { getComponent, raxGetWrappedComponent } from 'ykfe-utils'
import { getComponent } from 'ykfe-utils'
import raxGetWrappedComponent from 'ykfe-utils/lib/components/raxGetinitialProps'
import { createBrowserHistory } from 'history'
import Layout from '@/layout'
import { routes } from '../config/config.ssr'
Expand Down
4 changes: 1 addition & 3 deletions packages/ykfe-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ykfe-utils",
"version": "3.5.7",
"version": "3.5.8",
"description": "utils for ykfe",
"main": "lib/index.js",
"module": "es/index.js",
Expand All @@ -19,8 +19,6 @@
"lodash.clonedeepwith": "^4.5.0",
"merge-stream": "^2.0.0",
"path-to-regexp": "^6.1.0",
"rax": "^1.1.1",
"rax-server-renderer": "^1.1.6",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/ykfe-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import GetinitialProps from './components/getinitialProps'
import RaxGetinitialProps from './components/raxGetinitialProps'
import onlyCsr from './components/onlyCsr'
import getComponent from './getComponent'
import Loadable from './loadable'
Expand All @@ -8,7 +7,6 @@ import { preloadComponent } from './preloadComponent'
export {
GetinitialProps,
GetinitialProps as getWrappedComponent,
RaxGetinitialProps as raxGetWrappedComponent,
onlyCsr,
Loadable,
getComponent,
Expand Down
6 changes: 4 additions & 2 deletions packages/ykfe-utils/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { resolve } from 'path'
import { Readable, PassThrough } from 'stream'
import { Readable } from 'stream'
import React from 'react'
import { renderToNodeStream, renderToString as reactRenderToString } from 'react-dom/server'
import { Config } from '../interface/config'

const { renderToString } = require('rax-server-renderer')
const resolveDir = (path: string) => resolve(process.cwd(), path)

const logGreen = (text: string) => {
console.log(`\x1B[32m ${text}`)
}

const reactToStream = (Component: React.FunctionComponent, props: object, config: Config) => {
const { baseDir } = config
const BASE_DIR = baseDir || process.cwd()
if (config.useReactToString) {
return reactRenderToString(React.createElement(Component, props))
} else {
const renderToString = require(BASE_DIR + '/node_modules/rax-server-renderer').renderToString
return config.isRax ? renderToString(React.createElement(Component, props)) : renderToNodeStream(React.createElement(Component, props))
}
}
Expand Down

0 comments on commit 0a494c1

Please sign in to comment.