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

tarojs-react-generator

v1.5.0

Published

Taro 页面/组件创建工具,支持 Taro 3 + React

Downloads

18

Readme

tarojs-react-generator

Taro 页面/组件创建工具,支持 Taro 3 + React

安装

npm install tarojs-react-generator --save-dev

使用

修改项目 config/index.js 中的 plugins 配置

const config = {
  ...
  plugins: [
    ...
    ['tarojs-react-generator', {
      css: 'sass',
      cssModules: true
    }]
  ]
  ...
}

插件配置

| 参数项 | 类型 | 说明 | 默认值 | | :-----| :---- | :---- | :---- | | css | string | 指定 css 预处理器,可选 none, sass, less, stylus | sass| | cssModules | boolean | 是否开启 cssModules(只针对页面生效),可选 true, false | true | | typescript | boolean | 是否使用 typescript,可选 true, false | false | | hooks | boolean | 是否使用 hooks,可选 true, false | false | | createConfigFile | boolean | 是否单独创建页面配置文件,可选 true, false | true | | updateRouter | object | 创建页面后更新路由配置 | | | pageTpl | string | 自定义页面模板的路径,如'src/tpl/page.ejs',注入变量有 name, upperFirst, lowerFirst | 默认为'',不使用自定义模板 | | componentTpl | string | 自定义组件模板的路径,注入变量有 name, upperFirst, lowerFirst | 默认为'',不使用自定义模板 | | configTpl | string | 自定义配置模板的路径,注入变量有 name, upperFirst, lowerFirst | 默认为'',不使用自定义模板 | | styleTpl | string | 自定义样式模板的路径,注入变量有 name, isPage, upperFirst, lowerFirst | 默认为'',不使用自定义模板 |

updateRouter 参数

| 参数项 | 类型 | 说明 | 默认值 | | :-----| :---- | :---- | :---- | | enable | boolean | 是否开启,可选 true, false | true | | space | number | 插入位置缩进空格数 | 4 |

模板示例

src/tpl/page.ejs

/**
 * 模板注入变量
 * @param name: string 文件名
 * @param upperFirst: function 将首字母大写的函数
 * @param lowerFirst: function 将首字母小写的函数
 */
import { useEffect } from 'react'
import { View } from '@tarojs/components'
import styles from './index.module.scss'

function <%= upperFirst(name) %>() {

  return (
    <View className={styles.<%= name %>Page}>
      hello
    </View>
  )
}

export default <%= upperFirst(name) %>

src/tpl/style.ejs

<% if (isPage) { %>.<%= name %>Page {

}
<% } else { %>.<%= lowerFirst(name) %>Com {

}
<% } %>

命令行参数

| 参数项 | 类型 | 说明 | | :-----| :---- | :---- | | --com | string | 创建一个公共组件/页面组件 | | --page | string | 创建一个页面 |

示例

创建公共组件
taro g --com Button
创建页面组件(index为页面文件夹名称)
taro g --com index/Button  
创建页面
taro g --page mine
-- 页面:pages/mine/index.tsx
-- 配置:pages/mine/index.config.tsx
-- 样式:pages/mine/index.module.scss
创建页面(指定路径)
taro g --page index/bannerDetail
-- 页面:pages/index/bannerDetail/index.tsx
-- 配置:pages/index/bannerDetail/index.config.tsx
-- 样式:pages/index/bannerDetail/index.module.scss