代码拉取完成,页面将自动刷新
提供 taroConfig 和 CustomProjectConfig 以辅助 Taro 开发。
整合 taro3-config-helper 和 taro-custom-project-config-plugin ,并用 typescript 重构。
taroConfig
cross-env PROJECT=project MODE=dev taro build --type weapp
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
,配置文件列表检索顺序如下(先匹配文件存在的则作为当前环境的小程序配置文件):
注意
babel.config.js
和 tsconfig.json
文件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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。