Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
418 additions
and
266 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,12 +1,57 @@ | ||
import { resolve } from 'path' | ||
import { _ } from './underscore' | ||
import { Resolver, createResolver } from './resolver' | ||
import { SanData } from './san-data' | ||
import { Emitter } from '../utils/emitter' | ||
import { readStringSync } from '../utils/fs' | ||
|
||
export const RUNTIME_FILES = [ | ||
/** | ||
* 编译成源代码时,需要包含的运行时文件 | ||
*/ | ||
const RUNTIME_FILES = [ | ||
resolve(__dirname, '../../dist/runtime/underscore.js'), | ||
resolve(__dirname, '../../dist/runtime/san-data.js') | ||
resolve(__dirname, '../../dist/runtime/san-data.js'), | ||
resolve(__dirname, '../../dist/runtime/resolver.js') | ||
] | ||
|
||
export function createRuntime () { | ||
return { _, SanData } | ||
export interface SanSSRRuntime { | ||
/** | ||
* 无状态的工具库,类似 lodash | ||
*/ | ||
_: typeof _ | ||
/** | ||
* SanData 的 SSR 运行时替代品 | ||
*/ | ||
SanData: typeof SanData | ||
/** | ||
* 组件 render、Class 解析器 | ||
*/ | ||
resolver: Resolver | ||
/** | ||
* 当前目标文件的 exports 对象 | ||
*/ | ||
exports: { [key: string]: any } | ||
} | ||
|
||
/** | ||
* 产出运行时代码 | ||
*/ | ||
export function emitRuntime (emitter: Emitter) { | ||
emitter.writeLine(`var sanSSRRuntime = { exports };`) | ||
for (const file of RUNTIME_FILES) { | ||
emitter.writeLine(`!(function (exports) {`) | ||
emitter.indent() | ||
emitter.writeLines(readStringSync(file)) | ||
emitter.unindent() | ||
emitter.writeLine(`})(sanSSRRuntime);`) | ||
} | ||
emitter.writeLine(`sanSSRRuntime.resolver = sanSSRRuntime.createResolver(exports)`) | ||
} | ||
|
||
/** | ||
* 编译成 render 函数时,使用的 helper | ||
*/ | ||
export function createRuntime (): SanSSRRuntime { | ||
const exports = {} | ||
return { _, SanData, resolver: createResolver(exports), exports } | ||
} |
Oops, something went wrong.