npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webick

v0.1.9

Published

a react web frame

Downloads

7

Readme

Webick

介绍

一个使用React具有服务端渲染、约定式路由等功能的前端框架


快速开始

该框架并非纯前端框架,需要搭配 Node.js 使用

你可以使用create-rubick-app来快速获取一个使用 webick 与 snest 搭建的项目来学习如何使用webick

$ npm init rubick-app yourprojectname

目录结构

.
├── dist # 构建产物
│   ├── client # 存放前端静态资源文件
│   ├── server # 存放 external 后的服务端 bundle
│   ├── create-context.ts # 全局context生成文件
│   └── feRoutes.js # 读取pages路径生成的路由文件
├── src # 存放服务端 Node.js 相关代码
│   ├── client # 存放前端相关代码
│   │   ├── components # 存放公共组件
│   │   ├── pages
│   │   │   ├── index # index文件夹映射为根路由 /index => /
│   │   │   │   ├── render.tsx # 页面渲染逻辑
│   │   │   │   └── fetch.ts # 获取数据
│   │   │   └── list$id # 映射路由为 /list/:id
│   │   │       ├── render.tsx
│   │   │       ├── fetch.ts
│   │   │       └── detail # 映射路由为 /list/:id/detail
│   │   │           ├── render.tsx
│   │   │           └── fetch.ts
│   │   └── layout.tsx # 页面html布局
│   └── server # 存放服务端 Node.js 相关代码
├── package.json
└── tsconfig.json

前端约定式路由

通过约定式的文件夹结构来自动生成前端路由的配置

根据 /src/client/pages 文件夹来解析前端路由结构,pages 文件夹下的每个文件夹都被视为一个页面,约定规则可以参考上一节目录结构里 pages 下的目录结构

而在服务端,你只需要在需要渲染页面的路由下调用 render 方法,将请求上下午 ctx 做为参数传入,之后将会返回经过服务端渲染好的html 结构

import { Controller, Get, Context } from 'snest';
import { render } from 'webick';

@Controller()
class Home {
  constructor() {}

  @Get()
  async index(ctx: Context) {
    ctx.body = await render(ctx);
  }
}

数据获取

每个页面文件夹下的 fetch.ts 文件会做为该页面组件数据获取的入口,返回的数据会做为 props 传给页面组件

调用时机

在服务端渲染执行的时候,将会调用 fetch,并将数据注入到 window 中,在客户端渲染的时候会复用数据。然后在客户端进行前端路由跳转的时候会调用对应页面的 fetch

方法入参

interface RouterParams {
  path: string;
  search: string;
  params: any;
}

interface FetchParams<T> {
  routerParams: RouterParams;
  ctx?: MContext<T>;
  _isClient: boolean;
}

type FetchFunc<T = {}> = (params: FetchParams<T>) => Promise<any>;