-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support without document file (#546)
* feat: support without document file * fix: generate html * feat: ssr * chore: remove useless version
- Loading branch information
Showing
45 changed files
with
990 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# basic-without-document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"targets": ["web"], | ||
"web": { | ||
"ssr": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "with-rax", | ||
"description": "rax example", | ||
"dependencies": { | ||
"rax": "^1.1.0", | ||
"rax-document": "^0.1.0", | ||
"rax-image": "^2.0.0", | ||
"rax-link": "^1.0.1", | ||
"rax-text": "^1.0.0", | ||
"rax-view": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/rax": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"start": "rax-app start", | ||
"build": "rax-app build" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"routes": [ | ||
{ | ||
"path": "/", | ||
"source": "pages/Home/index" | ||
}, | ||
{ | ||
"path": "/about", | ||
"source": "pages/About/index", | ||
"window": { | ||
"title": "About Page" | ||
} | ||
} | ||
], | ||
"window": { | ||
"title": "Rax App" | ||
}, | ||
"metas": ["<meta name=\"description\" content=\"150 words\" />"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createElement } from 'rax'; | ||
import { runApp } from 'rax-app'; | ||
|
||
runApp(); |
5 changes: 5 additions & 0 deletions
5
examples/basic-without-document/src/components/Logo/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.logo { | ||
width: 200rpx; | ||
height: 180rpx; | ||
margin-bottom: 20rpx; | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/basic-without-document/src/components/Logo/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createElement, PureComponent } from 'rax'; | ||
import Image from 'rax-image'; | ||
|
||
import './index.css'; | ||
|
||
class Logo extends PureComponent { | ||
render() { | ||
const source = { | ||
uri: 'https://img.alicdn.com/imgextra/i4/O1CN0145ZaIM1QEObAAbKa1_!!6000000001944-2-tps-1701-1535.png', | ||
}; | ||
console.log('with router =>', this.props); | ||
return ( | ||
<Image | ||
className="logo" | ||
source={source} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default Logo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.home { | ||
align-items: center; | ||
margin-top: 200rpx; | ||
} | ||
|
||
.title { | ||
font-size: 35rpx; | ||
font-weight: bold; | ||
margin: 20rpx 0; | ||
} | ||
|
||
.info { | ||
font-size: 36rpx; | ||
margin: 8rpx 0; | ||
color: #555; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createElement, Component } from 'rax'; | ||
import View from 'rax-view'; | ||
import Text from 'rax-text'; | ||
import { getSearchParams } from 'rax-app'; | ||
|
||
import './index.css'; | ||
|
||
class About extends Component { | ||
componentDidMount() { | ||
console.log('about search params', getSearchParams()); | ||
} | ||
|
||
onShow() { | ||
console.log('about show...'); | ||
} | ||
|
||
onHide() { | ||
console.log('about hide...'); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View className="about"> | ||
<Text className="title">About Page</Text> | ||
<Text className="info" onClick={() => (this.props as any).history.push('/')}>Go Home</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default About; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.home { | ||
align-items: center; | ||
margin-top: 200rpx; | ||
} | ||
|
||
.title { | ||
font-size: 35rpx; | ||
font-weight: bold; | ||
margin: 20rpx 0; | ||
} | ||
|
||
.info { | ||
font-size: 36rpx; | ||
margin: 8rpx 0; | ||
color: #555; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { createElement } from 'rax'; | ||
import { usePageShow, usePageHide, getSearchParams } from 'rax-app'; | ||
import View from 'rax-view'; | ||
import Text from 'rax-text'; | ||
import Logo from '@/components/Logo'; | ||
|
||
import './index.css'; | ||
|
||
export default function Home(props) { | ||
const { history } = props; | ||
|
||
const searchParams = getSearchParams(); | ||
|
||
console.log('home search params =>', searchParams); | ||
console.log('home page props =>', props); | ||
|
||
usePageShow(() => { | ||
console.log('home show...'); | ||
}); | ||
|
||
usePageHide(() => { | ||
console.log('home hide...'); | ||
}); | ||
|
||
return ( | ||
<View className="home"> | ||
<Logo /> | ||
<Text className="title">{props?.data?.title || 'Welcome to Your Rax App'}</Text> | ||
<Text className="info">{props?.data?.info || 'More information about Rax'}</Text> | ||
<Text className="info" onClick={() => history.push('/about', { id: 1 })}>Go About</Text> | ||
</View> | ||
); | ||
} | ||
|
||
Home.getInitialProps = async () => { | ||
return { | ||
data: { | ||
title: 'Welcome to Your Rax App with SSR', | ||
info: 'More information about Rax', | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"compileOnSave": false, | ||
"buildOnSave": false, | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "build", | ||
"module": "esnext", | ||
"target": "es6", | ||
"jsx": "preserve", | ||
"jsxFactory": "createElement", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["es6", "dom"], | ||
"sourceMap": true, | ||
"allowJs": true, | ||
"rootDir": "./", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": false, | ||
"importHelpers": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@/*": ["./src/*"], | ||
"rax-app": [".rax/index.ts"] | ||
} | ||
}, | ||
"include": ["src", ".rax"], | ||
"exclude": ["node_modules", "build", "public"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
{ | ||
"compileOnSave": false, | ||
"buildOnSave": false, | ||
"compilerOptions": { | ||
"module": "esNext", | ||
"target": "es2015", | ||
"baseUrl": ".", | ||
"outDir": "build", | ||
"jsx": "react", | ||
"module": "esnext", | ||
"target": "es6", | ||
"jsx": "preserve", | ||
"jsxFactory": "createElement", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["es6", "dom"], | ||
"sourceMap": true, | ||
"alwaysStrict": true, | ||
"baseUrl": ".", | ||
"allowJs": true, | ||
"rootDir": "./", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": false, | ||
"importHelpers": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@/*": ["./src/*"], | ||
"rax-app": [".rax/index.ts"], | ||
"rax": ["node_modules/@types/rax"] | ||
"rax-app": [".rax/index.ts"] | ||
} | ||
}, | ||
"include": ["src/*", ".rax"], | ||
"exclude": ["build"] | ||
"include": ["src", ".rax"], | ||
"exclude": ["node_modules", "build", "public"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
declare module 'error-stack-tracey' { | ||
export function parse(error: object, bundleContent: string): object; | ||
export function parse(error: object, bundleContent: string): any[]; | ||
export function print(message: string, stackFrame: any[]): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/plugin-rax-web/src/DocumentPlugin/builtInLoader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as qs from 'qs'; | ||
import * as fs from 'fs'; | ||
import { formatPath } from '@builder/app-helpers'; | ||
import { IBuiltInDocumentQuery } from '../types'; | ||
|
||
/** | ||
* loader for wrap document and pages to be server render function, which can render page to html | ||
*/ | ||
export default function () { | ||
const query: IBuiltInDocumentQuery = typeof this.query === 'string' ? qs.parse(this.query.substr(1)) : this.query; | ||
const { staticExportPagePath, builtInDocumentTpl } = query; | ||
|
||
const formatedPagePath = staticExportPagePath ? formatPath(staticExportPagePath) : null; | ||
const needStaicExport = formatedPagePath && fs.existsSync(formatedPagePath); | ||
let source; | ||
|
||
if (needStaicExport) { | ||
source = ` | ||
import { createElement } from 'rax'; | ||
import renderer from 'rax-server-renderer'; | ||
import Page from '${formatedPagePath}'; | ||
export function renderInitialHTML(assets) { | ||
const contentElement = createElement(Page, {}); | ||
const initialHtml = contentElement ? renderer.renderToString(contentElement, { | ||
defaultUnit: 'rpx' | ||
}) : ''; | ||
return initialHtml; | ||
} | ||
`; | ||
} else { | ||
source = ` | ||
export const renderInitialHTML = () => ''; | ||
`; | ||
} | ||
source += `\n export const html = \`${builtInDocumentTpl}\`;`; | ||
return source; | ||
} |
Oops, something went wrong.