├── .editorconfig
├── .env.development
├── .env.production
├── .env.test
├── .gitignore
├── .husky
├── commit-msg
└── pre-commit
├── .npmrc
├── .vscode
├── extensions.json
└── settings.json
├── LICENSE
├── README.assets
└── introduce.png
├── README.md
├── __tests__
└── index.test.js
├── babel.config.js
├── config
├── dev.ts
├── envConfig.ts
├── index.ts
└── prod.ts
├── eslint.config.mjs
├── jest.config.ts
├── package.json
├── pnpm-lock.yaml
├── project.alipay.json
├── project.config.json
├── project.tt.json
├── src
├── api
│ ├── README.md
│ ├── core
│ │ ├── apiFactory.ts
│ │ └── queryKeys.ts
│ ├── endpoints
│ │ ├── user.ts
│ │ └── wechat.ts
│ ├── hooks
│ │ ├── useUser.ts
│ │ └── useWechat.ts
│ ├── index.ts
│ ├── models
│ │ ├── user.ts
│ │ └── wechat.ts
│ └── wechat.ts
├── app.config.ts
├── app.scss
├── app.tsx
├── cache.ts
├── components
│ ├── FloatingButton
│ │ └── index.tsx
│ ├── InfiniteScroll
│ │ └── index.tsx
│ ├── InputPopup
│ │ └── index.tsx
│ ├── KeyboardAdaptivePopup
│ │ └── index.tsx
│ ├── ListItem
│ │ └── index.tsx
│ ├── LoadingAnimation
│ │ ├── index.tsx
│ │ └── styles.scss
│ ├── PageWrapper
│ │ ├── BottomActions.tsx
│ │ ├── Navigation.tsx
│ │ ├── NavigationMenu.tsx
│ │ ├── index.tsx
│ │ └── types.ts
│ ├── Pagination
│ │ └── index.tsx
│ └── PrivacyPolicyPopup
│ │ └── index.tsx
├── constants
│ ├── routeTypes.ts
│ ├── routes.ts
│ ├── scene.ts
│ └── themes.ts
├── hooks
│ ├── useDebounce.ts
│ ├── useFormValidation.ts
│ ├── usePagination.ts
│ └── useTheme.ts
├── index.html
├── lib
│ └── react-query.ts
├── pages
│ ├── agreements
│ │ ├── privacy-policy.tsx
│ │ └── user-agreement.tsx
│ ├── index
│ │ ├── index.config.ts
│ │ ├── index.scss
│ │ └── index.tsx
│ └── profile
│ │ ├── ProfileSettingsGroup.tsx
│ │ ├── ProfileSettingsItem.tsx
│ │ ├── index.scss
│ │ └── index.tsx
├── sr.config.ts
├── types
│ ├── index.ts
│ └── response.ts
└── utils
│ ├── authUtils.ts
│ ├── bll
│ └── user.ts
│ ├── cache
│ ├── README.md
│ ├── index.ts
│ └── types.ts
│ ├── env.ts
│ ├── eventBus.ts
│ ├── friendUtils.ts
│ ├── httpClient
│ ├── apiClient.ts
│ ├── auth
│ │ ├── index.ts
│ │ ├── interceptor.ts
│ │ └── token.ts
│ ├── constants.ts
│ └── index.ts
│ ├── index.ts
│ ├── login.ts
│ ├── route.ts
│ ├── timeFormatter.ts
│ ├── treeHelper.ts
│ ├── typeChecks.ts
│ ├── updateVersion.ts
│ ├── validation.ts
│ └── zodErrorMap.ts
├── tsconfig.json
├── types
└── global.d.ts
└── unocss.config.ts
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/.env.development:
--------------------------------------------------------------------------------
1 | # 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config
2 | # TARO_APP_ID="开发环境下的小程序appid"
--------------------------------------------------------------------------------
/.env.production:
--------------------------------------------------------------------------------
1 | # TARO_APP_ID="生产环境下的小程序appid"
--------------------------------------------------------------------------------
/.env.test:
--------------------------------------------------------------------------------
1 | # TARO_APP_ID="测试环境下的小程序appid"
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ######################
2 | # Project Specific
3 | ######################
4 | dist
5 | build
6 | dist-ssr
7 | *.local
8 | deploy_versions/
9 | .temp/
10 | .rn_temp/
11 | .swc
12 |
13 | ######################
14 | # Node
15 | ######################
16 | /node/
17 | node_tmp/
18 | node_modules/
19 | npm-debug.log.*
20 | yarn-debug.log*
21 | yarn-error.log*
22 | pnpm-debug.log*
23 | lerna-debug.log*
24 | /.awcache/*
25 | /.cache-loader/*
26 |
27 | ######################
28 | # SASS
29 | ######################
30 | .sass-cache/
31 |
32 | ######################
33 | # Eclipse
34 | ######################
35 | *.pydevproject
36 | .project
37 | .metadata
38 | tmp/
39 | tmp/**/*
40 | *.tmp
41 | *.bak
42 | *.swp
43 | *~.nib
44 | local.properties
45 | .classpath
46 | .settings/
47 | .loadpath
48 | .factorypath
49 | /src/main/resources/rebel.xml
50 |
51 | # External tool builders
52 | .externalToolBuilders/**
53 |
54 | # Locally stored "Eclipse launch configurations"
55 | *.launch
56 |
57 | # CDT-specific
58 | .cproject
59 |
60 | # PDT-specific
61 | .buildpath
62 |
63 | # STS-specific
64 | /.sts4-cache/*
65 |
66 | ######################
67 | # IntelliJ
68 | ######################
69 | .idea/
70 | *.iml
71 | *.iws
72 | *.ipr
73 | *.ids
74 | *.orig
75 | classes/
76 | out/
77 |
78 | ######################
79 | # Visual Studio Code
80 | ######################
81 | .vscode/*
82 | !.vscode/settings.json
83 | !.vscode/tasks.json
84 | !.vscode/launch.json
85 | !.vscode/extensions.json
86 | *.code-workspace
87 |
88 | ######################
89 | # Maven
90 | ######################
91 | /log/
92 | /target/
93 |
94 | ######################
95 | # Gradle
96 | ######################
97 | .gradle/
98 | /build/
99 |
100 | ######################
101 | # Package Files
102 | ######################
103 | *.jar
104 | *.war
105 | *.ear
106 | *.db
107 |
108 | ######################
109 | # Windows
110 | ######################
111 | # Windows image file caches
112 | Thumbs.db
113 |
114 | # Folder config file
115 | Desktop.ini
116 |
117 | ######################
118 | # Mac OSX
119 | ######################
120 | .DS_Store
121 | .svn
122 |
123 | # Thumbnails
124 | ._*
125 |
126 | # Files that might appear on external disk
127 | .Spotlight-V100
128 | .Trashes
129 |
130 | ######################
131 | # Directories
132 | ######################
133 | /bin/
134 | /deploy/
135 |
136 | ######################
137 | # Logs
138 | ######################
139 | logs
140 | *.log*
141 |
142 | ######################
143 | # Others
144 | ######################
145 | *.class
146 | *.*~
147 | *~
148 | .merge_file*
149 |
150 | ######################
151 | # Gradle Wrapper
152 | ######################
153 | !gradle/wrapper/gradle-wrapper.jar
154 |
155 | ######################
156 | # Maven Wrapper
157 | ######################
158 | !.mvn/wrapper/maven-wrapper.jar
159 |
160 | ######################
161 | # ESLint
162 | ######################
163 | .eslintcache
164 |
165 | ######################
166 | # Code coverage
167 | ######################
168 | /coverage/
169 | /.nyc_output/
170 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | echo "husky commit-msg-lint start"
2 | npx --no-install commitlint --edit $1
3 | echo "husky commit-msg-lint end"
4 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | echo "husky lint-staged start"
2 | pnpm lint-staged
3 | echo "husky lint-staged end"
4 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-manager-strict=false
2 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["johnsoncodehk.volar", "dbaeumer.vscode-eslint"]
3 | }
4 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | // Enable the ESlint flat config support
3 | "eslint.experimental.useFlatConfig": true,
4 |
5 | // Disable the default formatter, use eslint instead
6 | "prettier.enable": false,
7 | "editor.formatOnSave": false,
8 |
9 | // Auto fix
10 | "editor.codeActionsOnSave": {
11 | "source.fixAll.eslint": "explicit",
12 | "source.organizeImports": "never"
13 | },
14 |
15 | // Silent the stylistic rules in you IDE, but still auto fix them
16 | "eslint.rules.customizations": [
17 | { "rule": "style/*", "severity": "off" },
18 | { "rule": "*-indent", "severity": "off" },
19 | { "rule": "*-spacing", "severity": "off" },
20 | { "rule": "*-spaces", "severity": "off" },
21 | { "rule": "*-order", "severity": "off" },
22 | { "rule": "*-dangle", "severity": "off" },
23 | { "rule": "*-newline", "severity": "off" },
24 | { "rule": "*quotes", "severity": "off" },
25 | { "rule": "*semi", "severity": "off" }
26 | ],
27 |
28 | // Enable eslint for all supported languages
29 | "eslint.validate": [
30 | "javascript",
31 | "javascriptreact",
32 | "typescript",
33 | "typescriptreact",
34 | "vue",
35 | "html",
36 | "markdown",
37 | "json",
38 | "jsonc",
39 | "yaml"
40 | ]
41 | }
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Kirk Lin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.assets/introduce.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirklin/boot-taro-react/da60d0c7abd811fd6c561599adccd8a270824ce8/README.assets/introduce.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
Boot Taro React
3 |

4 |
5 |
6 | [](https://github.com/kirklin)
7 | [](https://github.com/kirklin/boot-taro-react/blob/main/LICENSE)
8 | [](https://github.com/kirklin/boot-taro-react/stargazers)
9 | [](https://github.com/kirklin/boot-taro-react/network/members)
10 | [](https://github.com/kirklin/boot-taro-react/issues)
11 |
12 | 一个基于 Taro + React 的开箱即用的小程序模板,采用最新的 Taro 4.0 + React 18 + TypeScript + UnoCSS 等主流技术栈。
13 |
14 | ## ✨ 特性
15 |
16 | - 🎯 **最新技术栈**:使用 Taro 4.0 + React 18 + TypeScript + UnoCSS 等前沿技术开发
17 | - 📱 **多端适配**:支持微信、支付宝、百度、字节跳动、QQ、京东等小程序平台和 H5
18 | - 🎨 **Taroify**:集成了 Taroify UI 组件库,提供丰富的组件和优秀的开发体验
19 | - 🚀 **原子化 CSS**:采用 UnoCSS,享受高效的样式开发体验
20 | - 🔍 **TypeScript**:应用程序级 JavaScript 的语言
21 | - 📦 **状态管理**:集成了 React Query,轻松管理服务端状态
22 | - 🔧 **最佳实践**:良好的工程化实践,包括 eslint、stylelint、commitlint、husky 等
23 |
24 | ## 🚀 开发工具链
25 |
26 | - ⚡️ [React 18](https://beta.reactjs.org/)
27 | - 🛠️ [TypeScript](https://www.typescriptlang.org/)
28 | - 📱 [Taro 4](https://taro.zone/)
29 | - 🎨 [UnoCSS](https://github.com/unocss/unocss) - 高性能且极具灵活性的即时原子化 CSS 引擎
30 | - 🌼 [Taroify](https://taroify.gitee.io/taroify.com/introduce/) - 基于 Taro 的多端 UI 组件库
31 | - 🔍 [ESLint](https://eslint.org/) - 代码检查
32 | - 🎯 [Commitlint](https://commitlint.js.org/) - Git 提交规范
33 |
34 | ## 📦 使用
35 |
36 | ### 环境准备
37 |
38 | - Node.js 18+
39 | - pnpm 9.15.0+
40 |
41 | ### 安装依赖
42 |
43 | ```bash
44 | pnpm install
45 | ```
46 |
47 | ### 运行
48 |
49 | ```bash
50 | # 微信小程序
51 | pnpm dev:weapp
52 |
53 | # H5
54 | pnpm dev:h5
55 | ```
56 |
57 | ### 构建
58 |
59 | ```bash
60 | # 微信小程序
61 | pnpm build:weapp
62 |
63 | # H5
64 | pnpm build:h5
65 | ```
66 |
67 | ## 🎨 项目结构
68 |
69 | ```bash
70 | ├── src
71 | │ ├── api # API 接口
72 | │ ├── components # 公共组件
73 | │ ├── constants # 常量定义
74 | │ ├── hooks # 自定义 Hooks
75 | │ ├── pages # 页面
76 | │ ├── types # 类型定义
77 | │ ├── utils # 工具函数
78 | │ ├── app.config.ts # Taro 应用配置
79 | │ ├── app.scss # 全局样式
80 | │ └── app.tsx # 应用入口
81 | ├── config # 项目配置
82 | ├── types # 全局类型定义
83 | ├── .eslintrc.js # ESLint 配置
84 | ├── .prettierrc # Prettier 配置
85 | ├── tsconfig.json # TypeScript 配置
86 | └── package.json # 项目依赖
87 | ```
88 |
89 | ## 📄 开源协议
90 |
91 | [MIT](./LICENSE) License © 2024 [Kirk Lin](https://github.com/kirklin)
92 |
--------------------------------------------------------------------------------
/__tests__/index.test.js:
--------------------------------------------------------------------------------
1 | import TestUtils from "@tarojs/test-utils-react";
2 |
3 | // eslint-disable-next-line no-undef
4 | describe("testing", () => {
5 | // eslint-disable-next-line no-undef
6 | it("test", async () => {
7 | const testUtils = new TestUtils();
8 | await testUtils.createApp();
9 | await testUtils.PageLifecycle.onShow("pages/index/index");
10 | // eslint-disable-next-line no-undef
11 | expect(testUtils.html()).toMatchSnapshot();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | // babel-preset-taro 更多选项和默认值:
2 | // https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
3 | module.exports = {
4 | presets: [
5 | ["taro", {
6 | framework: "react",
7 | ts: true,
8 | }],
9 | ],
10 | plugins: [
11 | [
12 | "import",
13 | {
14 | libraryName: "@taroify/core",
15 | libraryDirectory: "",
16 | style: true,
17 | },
18 | "@taroify/core",
19 | ],
20 | [
21 | "import",
22 | {
23 | libraryName: "@taroify/icons",
24 | libraryDirectory: "",
25 | camel2DashComponentName: false,
26 | style: () => "@taroify/icons/style",
27 | },
28 | "@taroify/icons",
29 | ],
30 | ],
31 | };
32 |
--------------------------------------------------------------------------------
/config/dev.ts:
--------------------------------------------------------------------------------
1 | import type { UserConfigExport } from "@tarojs/cli";
2 |
3 | export default {
4 | logger: {
5 | quiet: false,
6 | stats: true,
7 | },
8 | mini: {
9 | webpackChain: (chain) => {
10 | chain.merge({
11 | plugin: {
12 | install: {
13 | // eslint-disable-next-line ts/no-require-imports
14 | plugin: require("terser-webpack-plugin"),
15 | args: [
16 | {
17 | terserOptions: {
18 | compress: true, // 默认使用terser压缩
19 | // mangle: false,
20 | keep_classnames: true, // 不改变class名称
21 | keep_fnames: true, // 不改变函数名称
22 | },
23 | },
24 | ],
25 | },
26 | },
27 | });
28 | },
29 | },
30 | h5: {},
31 | } satisfies UserConfigExport;
32 |
--------------------------------------------------------------------------------
/config/envConfig.ts:
--------------------------------------------------------------------------------
1 | // 定义环境变量的类型
2 | interface EnvConfig {
3 | TARO_ENV: string;
4 | NODE_ENV: string;
5 | AUTHOR: string;
6 | }
7 |
8 | // 设置环境变量的默认值
9 | const defaultEnvVars: EnvConfig = {
10 | TARO_ENV: "weapp",
11 | NODE_ENV: "production",
12 | AUTHOR: "Kirk Lin",
13 | };
14 |
15 | // 定义获取格式化日期时间字符串的函数
16 | function getFormattedDatePart(value: number): string {
17 | return value.toString().padStart(2, "0");
18 | }
19 |
20 | function getVersion(): string {
21 | const date = new Date();
22 | return [
23 | date.getFullYear(),
24 | getFormattedDatePart(date.getMonth() + 1),
25 | getFormattedDatePart(date.getDate()),
26 | getFormattedDatePart(date.getHours()),
27 | getFormattedDatePart(date.getMinutes()),
28 | getFormattedDatePart(date.getSeconds()),
29 | ].join("");
30 | }
31 |
32 | // 设置环境变量
33 | function setupEnv(): void {
34 | Object.keys(defaultEnvVars).forEach((key) => {
35 | // 使用 as 断言确保类型正确
36 | (process.env as any)[key] = (process.env as any)[key] ?? defaultEnvVars[key];
37 | });
38 | }
39 |
40 | // 获取版本号,使用类型注解
41 | const version: string = (process.env.VERSION as string) || getVersion();
42 |
43 | // 打印环境变量和版本号的函数
44 | function logEnv(): void {
45 | console.debug("Template Author:", process.env.AUTHOR);
46 | console.debug("TaroEnv:", process.env.TARO_ENV);
47 | console.debug("NodeEnv:", process.env.NODE_ENV);
48 | console.debug("Version:", version);
49 | console.debug();
50 | }
51 |
52 | // 导出setupEnv和logEnv函数,以及version变量
53 | export { logEnv, setupEnv, version };
54 |
--------------------------------------------------------------------------------
/config/index.ts:
--------------------------------------------------------------------------------
1 | import type { UserConfigExport } from "@tarojs/cli";
2 | import { resolve } from "node:path";
3 | import { defineConfig } from "@tarojs/cli";
4 | import { createSwcRegister, getModuleDefaultExport } from "@tarojs/helper";
5 | import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
6 | import devConfig from "./dev";
7 | import { logEnv, setupEnv } from "./envConfig";
8 | import prodConfig from "./prod";
9 |
10 | // 设置环境变量
11 | setupEnv();
12 |
13 | // 打印环境变量和版本号
14 | logEnv();
15 |
16 | // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
17 | export default defineConfig(async (merge) => {
18 | createSwcRegister({
19 | only: [filePath => filePath.includes("@unocss")],
20 | });
21 | const UnoCSS = getModuleDefaultExport(await import("@unocss/webpack"));
22 | const baseConfig: UserConfigExport = {
23 | projectName: "_boot-taro-react_",
24 | date: "2025-01-21",
25 | designWidth: 750,
26 | deviceRatio: {
27 | 640: 2.34 / 2,
28 | 750: 1,
29 | 375: 2,
30 | 828: 1.81 / 2,
31 | },
32 | alias: {
33 | "~": resolve(process.cwd(), "src"),
34 | },
35 | sourceRoot: "src",
36 | // 开启多端同步调试
37 | outputRoot: `dist/${process.env.TARO_ENV}`,
38 | plugins: ["@taro-hooks/plugin-react", "@tarojs/plugin-html"],
39 | defineConstants: {
40 | },
41 | copy: {
42 | patterns: [
43 | ],
44 | options: {
45 | },
46 | },
47 | framework: "react",
48 | compiler: "webpack5",
49 | cache: {
50 | enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
51 | },
52 | mini: {
53 | baseLevel: 8,
54 | postcss: {
55 | pxtransform: {
56 | enable: true,
57 | config: {
58 |
59 | },
60 | },
61 | url: {
62 | enable: true,
63 | config: {
64 | limit: 1024, // 设定转换尺寸上限
65 | },
66 | },
67 | cssModules: {
68 | enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
69 | config: {
70 | namingPattern: "module", // 转换模式,取值为 global/module
71 | generateScopedName: "[name]__[local]___[hash:base64:5]",
72 | },
73 | },
74 | },
75 | // https://github.com/NervJS/taro/issues/7160
76 | miniCssExtractPluginOption: {
77 | ignoreOrder: true,
78 | },
79 | optimizeMainPackage: {
80 | enable: true,
81 | },
82 | webpackChain(chain) {
83 | chain.resolve.plugin("tsconfig-paths").use(TsconfigPathsPlugin);
84 | chain.plugin("unocss").use(UnoCSS());
85 | },
86 | },
87 | h5: {
88 | publicPath: "/",
89 | staticDirectory: "static",
90 | esnextModules: ["@taroify"],
91 | output: {
92 | filename: "js/[name].[hash:8].js",
93 | chunkFilename: "js/[name].[chunkhash:8].js",
94 | },
95 | miniCssExtractPluginOption: {
96 | ignoreOrder: true,
97 | filename: "css/[name].[hash].css",
98 | chunkFilename: "css/[name].[chunkhash].css",
99 | },
100 | router: {
101 | mode: "browser",
102 | },
103 | devServer: {
104 | port: 8888,
105 | hot: false,
106 | host: "0.0.0.0",
107 | historyApiFallback: true,
108 | headers: {
109 | "Access-Control-Allow-Origin": "*", // 表示允许跨域
110 | },
111 | },
112 | postcss: {
113 | autoprefixer: {
114 | enable: true,
115 | config: {},
116 | },
117 | cssModules: {
118 | enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
119 | config: {
120 | namingPattern: "module", // 转换模式,取值为 global/module
121 | generateScopedName: "[name]__[local]___[hash:base64:5]",
122 | },
123 | },
124 | },
125 | webpackChain(chain) {
126 | chain.resolve.plugin("tsconfig-paths").use(TsconfigPathsPlugin);
127 | chain.plugin("unocss").use(UnoCSS());
128 | },
129 | },
130 | rn: {
131 | appName: "_boot-taro-react_",
132 | postcss: {
133 | cssModules: {
134 | enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
135 | },
136 | },
137 | },
138 | };
139 | if (process.env.NODE_ENV === "development") {
140 | // 本地开发构建配置(不混淆压缩)
141 | return merge({}, baseConfig, devConfig);
142 | }
143 | // 生产构建配置(默认开启压缩混淆等)
144 | return merge({}, baseConfig, prodConfig);
145 | });
146 |
--------------------------------------------------------------------------------
/config/prod.ts:
--------------------------------------------------------------------------------
1 | import type { UserConfigExport } from "@tarojs/cli";
2 |
3 | export default {
4 | mini: {
5 | enableSourceMap: false,
6 | },
7 | h5: {
8 | /**
9 | * WebpackChain 插件配置
10 | * @docs https://github.com/neutrinojs/webpack-chain
11 | */
12 | // webpackChain (chain) {
13 | // /**
14 | // * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
15 | // * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
16 | // */
17 | // chain.plugin('analyzer')
18 | // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
19 | // /**
20 | // * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
21 | // * @docs https://github.com/chrisvfritz/prerender-spa-plugin
22 | // */
23 | // const path = require('path')
24 | // const Prerender = require('prerender-spa-plugin')
25 | // const staticDir = path.join(__dirname, '..', 'dist')
26 | // chain
27 | // .plugin('prerender')
28 | // .use(new Prerender({
29 | // staticDir,
30 | // routes: [ '/pages/index/index' ],
31 | // postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
32 | // }))
33 | // }
34 | },
35 | } satisfies UserConfigExport;
36 |
--------------------------------------------------------------------------------
/eslint.config.mjs:
--------------------------------------------------------------------------------
1 | import kirklin from "@kirklin/eslint-config";
2 |
3 | export default kirklin({
4 | rules: {
5 | "node/prefer-global/process": "off",
6 | "no-console": "off",
7 | "style/multiline-ternary": "off",
8 | },
9 | formatters: {
10 | /**
11 | * 格式化CSS、LESS、SCSS文件,以及Vue中的`