2 Star 0 Fork 0

K. / taro3-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Taro3 辅助库

介绍

提供 taroConfig 和 CustomProjectConfig 以辅助 Taro 开发。

整合 taro3-config-helpertaro-custom-project-config-plugin ,并用 typescript 重构。

taroConfig

  • 为项目提供更简易的方式创建 Taro 项目的配置,即可用于多项目模式,也可用于单项目模式。
  • 提供 npm 命令解析以提取出相应的 项目名称、版本号、运行模式、自定义运行环境,包含两种模式:
    • 基于 npm run 指令解析提取,如:npm run project-name:platform:mode:custom-env
    • 基于 npm run 指令内容提取,如:npm run anything => cross-env PROJECT=project MODE=dev taro build --type weapp
  • 提供对应 callback 可重载 项目根目录、源代码根目录、输出根目录、输出文件夹名称。

CustomProjectConfig

基于 taro 插件机制 开发,无缝嵌入 taro 流程。

提供根据项目的 运行模式(development or production) 和 自定义运行环境,加载不同小程序配置文件,并监控该文件的改变。

该插件主要为了解决多人合作式开发时,不同开发者的项目配置文件之间的冲突合并问题。

同时也为了将 PROD 模式的小程序配置文件彻底固化,能更高效的进行小程序的编译和发布。

安装教程

npm i taro3-utils --save-dev
yarn add taro3-utils -D

使用说明

const { resolve } = require('path');
const { taroConfig, customProjectConfig, deepMerge, ArrayMergeMode } = require('taro3-utils');
// ArrayMergeMode = COMBINE | REPLACE | MERGE
// arrayMode.default = ArrayMergeMode.MERGE

// others export methods
// const { isExistDir, isExistFile, isEmptyString, filterExistFiles } = require('taro3-utils');
// const { extractProjectInfo, parseNpmCommand, RuntimeMode, filterRuntimeMode } = require('taro3-utils');

module.exports = function (merge) {
  const { config, info } = taroConfig({
    root  : 'any-path',
    config: deepMerge([
      require('./base-config'),
      info.mode === 'dev' ? require('./dev') : require('./prod'),
    ], { arrayMode: ArrayMergeMode.COMBINE })
  });

  config.plugins.push(
    customProjectConfig({
      configRoot: resolve(info.projectRoot, 'miniprogram'),
      outputRoot: info.outputRoot,
    })
  );

  return config;
};

在项目中创建 miniprogram 目录,添加对应平台的小程序配置文件:

weapp.json
weapp.dev.json
weapp.prod.json
weapp.dev.user.json
tt.json

假定执行的指令为:npm run any-project:weapp:dev:jacky ,配置文件列表检索顺序如下(先匹配文件存在的则作为当前环境的小程序配置文件):

  • weapp.dev.jacky.json
  • weapp.jacky.json
  • weapp.dev.json
  • weapp.json

注意

  1. 多项目环境,需要在项目根目录添加 babel.config.jstsconfig.json 文件
  2. global.d.ts 文件,添加如下内容:
// taro 原有内容
declare module '*.png';
declare module '*.gif';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.svg';
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.styl';

declare namespace NodeJS {
  interface ProcessEnv {
    TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
  }
}

// 添加全局常量
declare const AppName: string;
declare const AppVersion: string;
declare const AppMode: 'dev' | 'prod';
declare const AppPlatform: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd';
declare const AppCustom: string;
MIT License Copyright (c) 2021 K. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Taro3 辅助库 展开 收起
TypeScript 等 2 种语言
MIT
取消

发行版 (2)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/janpoem/taro3-utils.git
git@gitee.com:janpoem/taro3-utils.git
janpoem
taro3-utils
taro3-utils
master

搜索帮助