Skip to content

Commit

Permalink
feat(add personal taro-runtime): fix runtime lifestyle error
Browse files Browse the repository at this point in the history
  • Loading branch information
innocces committed Jul 7, 2021
1 parent f58e54e commit fb0a21f
Show file tree
Hide file tree
Showing 59 changed files with 6,977 additions and 0 deletions.
1 change: 1 addition & 0 deletions .umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
alias: {
'@tarojs/components$': '@tarojs/components/dist-h5/react',
'@tarojs/taro': '@tarojs/taro-h5',
'@tarojs/runtime': '@taro-hooks/website-runtime',
'@pages': __dirname + '/packages/app/src/pages',
},
define: {
Expand Down
2 changes: 2 additions & 0 deletions packages/taro-runtime/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
lib
6 changes: 6 additions & 0 deletions packages/taro-runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lib
t.js
*.wxml
s.js
t.debug.ts
react
49 changes: 49 additions & 0 deletions packages/taro-runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# `@tarojs/runtime`

Taro 运行时。在小程序端连接框架(DSL)渲染机制到小程序渲染机制,连接小程序路由和生命周期到框架对应的生命周期。在 H5/RN 端连接小程序生命周期**规范**到框架生命周期。

## 核心 API

### createReactApp()

暴露给 `@tarojs/taro-loader/app` 调用,在小程序入口文件中调用,创建一个小程序 `App` 构造函数接受的小程序应用规范对象。

### createVueApp()

暴露给 `@tarojs/taro-loader/app` 调用,在小程序入口文件中调用,创建一个小程序 `App` 构造函数接受的小程序应用规范对象。

### createPageConfig()

暴露给 `@tarojs/taro-loader/page` 调用,在小程序页面文件中调用,创建一个小程序 `Page` 构造函数接受的小程序页面规范对象。

### window

在小程序端模仿浏览器的 `window` 实现的对象,在浏览器环境中返回浏览器本身的 `window`。此对象通过 Webpack 的 [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) 注入到全局对象以供第三方库调用。

### navigator

在小程序端模仿浏览器的 `navigator` 实现的对象,在浏览器环境中返回浏览器本身的 `navigator`。此对象通过 Webpack 的 [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) 注入到全局对象以供第三方库调用。

### document

在小程序端模仿浏览器的 `document` 实现的对象,在浏览器环境中返回浏览器本身的 `document`。此对象通过 Webpack 的 [ProvidePlugin](https://webpack.js.org/plugins/provide-plugin/) 注入到全局对象以供第三方库调用。

### Current

暴露给开发者的 Taro 全局变量,目前有三个属性:

- `Current.app`,返回当前小程序应用实例,非小程序端返回小程序规范应用实例,可通过此实例调用小程序规范生命周期。
- `Current.page`,返回当前小程序页面实例,非小程序端返回小程序规范页面实例,可通过此实例调用小程序规范生命周期。
- `Current.router`,返回当前小程序路由信息,非小程序端返回小程序规范路由信息

### options

Taro 配置:

- `html`: [渲染 HTML](https://taro-docs.jd.com/taro/next/docs/html.html)
- `debug`: 开启之后会打印渲染时间
- `prerender`: 暴露给 `@tarojs/cli` 的内部参数

### Events

[Taro 消息机制](https://nervjs.github.io/taro/docs/apis/about/events.html#docsNav)
42 changes: 42 additions & 0 deletions packages/taro-runtime/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { jsWithTs: tsjPreset } = require('ts-jest/presets');
const path = require('path');

module.exports = {
testEnvironment: 'node',
transform: {
...tsjPreset.transform,
},
transformIgnorePatterns: ['node_modules/(?!(lodash-es)/)'],
testURL: 'http://localhost/',
collectCoverage: false,
coveragePathIgnorePatterns: ['nerv.js', 'vue.js', 'utils.js'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
globals: {
'ts-jest': {
diagnostics: false,
tsConfig: {
jsx: 'react',
allowJs: true,
target: 'ES6',
},
},
},
testPathIgnorePatterns: ['node_modules', 'utils'],
moduleNameMapper: {
'@tarojs/shared': path.resolve(
__dirname,
'..',
'..',
'packages/shared/src/index.ts',
),
'@tarojs/react': path.resolve(
__dirname,
'..',
'..',
'packages/taro-react/dist/index.js',
),
},
// setupFiles: ['<rootDir>/__tests__/setup.js'],
testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'],
};
28 changes: 28 additions & 0 deletions packages/taro-runtime/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@taro-hooks/website-runtime",
"version": "3.2.15",
"description": "taro runtime for mini apps.",
"main": "dist/runtime.esm.js",
"module": "dist/runtime.esm.js",
"files": [
"dist"
],
"scripts": {
"test": "jest",
"build": "rollup -c",
"dev": "rollup -c -w"
},
"repository": {
"type": "git",
"url": "https://github.com/NervJS/taro/tree/master/packages/taro-runtime"
},
"author": "yuche",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@tarojs/shared": "3.2.15",
"lodash-es": "4.17.15"
}
}
39 changes: 39 additions & 0 deletions packages/taro-runtime/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { join } = require('path');
const buble = require('rollup-plugin-buble');
const typescript = require('rollup-plugin-typescript2');
const cwd = __dirname;

const baseConfig = {
input: join(cwd, 'src/index.ts'),
external: ['react', 'nervjs', 'react-dom', 'vue', '@tarojs/shared'],
output: [
{
file: join(cwd, 'dist/index.js'),
format: 'cjs',
sourcemap: true,
exports: 'named',
},
],
plugins: [typescript(), buble()],
};
const esmConfig = Object.assign({}, baseConfig, {
output: Object.assign({}, baseConfig.output, {
sourcemap: true,
format: 'es',
file: join(cwd, 'dist/runtime.esm.js'),
}),
plugins: baseConfig.plugins.slice(0, baseConfig.plugins.length - 1),
});

function rollup() {
const target = process.env.TARGET;

if (target === 'umd') {
return baseConfig;
} else if (target === 'esm') {
return esmConfig;
} else {
return [baseConfig, esmConfig];
}
}
module.exports = rollup();
Empty file.
2 changes: 2 additions & 0 deletions packages/taro-runtime/src/__tests__/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nerv.js
vue.js
Loading

0 comments on commit fb0a21f

Please sign in to comment.