first commit

This commit is contained in:
Tony 2024-03-15 14:39:20 +08:00
commit 246657408a
28 changed files with 12001 additions and 0 deletions

12
.editorconfig Normal file
View File

@ -0,0 +1,12 @@
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

10
.eslintrc Normal file
View File

@ -0,0 +1,10 @@
{
"extends": [
"taro/react"
],
"rules": {
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"import/no-commonjs": "off"
}
}

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
dist/
deploy_versions/
.temp/
.rn_temp/
node_modules/
.DS_Store
.swc

16
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
"tailwindCSS.experimental.classRegex": [
[
"cva\\(([^)]*)\\)",
"[\"'`]([^\"'`]*).*?[\"'`]"
],
[
"cx\\(([^)]*)\\)",
"(?:'|\"|`)([^']*)(?:'|\"|`)"
],
[
"clsx\\(([^)]*)\\)",
"(?:'|\"|`)([^']*)(?:'|\"|`)"
]
]
}

18
README.md Normal file
View File

@ -0,0 +1,18 @@
![logo](https://pic1.zhimg.com/v2-3ee20468f54bbfefcd0027283b21aaa8_720w.jpg?source=172ae18b)
# taro-react-tailwind-vscode-template
在 taro 里使用 tailwindcss 的模板项目
<!-- ## 命令行报错问题
Webpack5启动时报告Invalid option from onResolve() callback in plugin "scanImports": "importer"
这个是 tarojs 自己的问题,详见这个 [issues/13767](https://github.com/NervJS/taro/issues/13767) -->
> 记得关闭开发者工具 IDE 代码热重载
>
## 核心插件 [weapp-tailwindcss](https://github.com/sonofmagic/weapp-tailwindcss-webpack-plugin)
相关文档地址 <https://weapp-tw.icebreaker.top/>

10
babel.config.js Normal file
View File

@ -0,0 +1,10 @@
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
presets: [
['taro', {
framework: 'react',
ts: true
}]
]
}

9
config/dev.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = {
env: {
NODE_ENV: '"development"'
},
defineConstants: {
},
mini: {},
h5: {}
}

109
config/index.js Normal file
View File

@ -0,0 +1,109 @@
import { UnifiedWebpackPluginV5 } from "weapp-tailwindcss/webpack";
// const isH5 = process.env.TARO_ENV === "h5";
// const isApp = process.env.TARO_ENV === "rn";
// const WeappTailwindcssDisabled = isH5 || isApp;
const config = {
projectName: 'taro-react-tailwind-vscode-template',
date: '2023-5-6',
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
828: 1.81 / 2
},
sourceRoot: 'src',
outputRoot: 'dist',
plugins: [],
defineConstants: {
},
copy: {
patterns: [
],
options: {
}
},
framework: 'react',
compiler: {
type: 'webpack5',
prebundle: {
enable: false,
}
},
cache: {
enable: false // Webpack 持久化缓存配置建议开启。默认配置请参考https://docs.taro.zone/docs/config-detail#cache
},
mini: {
postcss: {
pxtransform: {
enable: true,
config: {
}
},
url: {
enable: true,
config: {
limit: 1024 // 设定转换尺寸上限
}
},
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
},
webpackChain(chain) {
chain.merge({
plugin: {
install: {
plugin: UnifiedWebpackPluginV5,
args: [
{
appType: 'taro',
// disabled: WeappTailwindcssDisabled,
rem2rpx: true
}
]
}
}
});
}
},
h5: {
publicPath: '/',
staticDirectory: 'static',
postcss: {
autoprefixer: {
enable: true,
config: {
}
},
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
},
rn: {
appName: 'taroDemo',
postcss: {
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
}
}
}
}
module.exports = function (merge) {
if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev'))
}
return merge({}, config, require('./prod'))
}

37
config/prod.js Normal file
View File

@ -0,0 +1,37 @@
module.exports = {
env: {
NODE_ENV: '"production"'
},
defineConstants: {
},
mini: {},
h5: {
/**
* WebpackChain 插件配置
* @docs https://github.com/neutrinojs/webpack-chain
*/
// webpackChain (chain) {
// /**
// * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
// * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
// */
// chain.plugin('analyzer')
// .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
// /**
// * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
// * @docs https://github.com/chrisvfritz/prerender-spa-plugin
// */
// const path = require('path')
// const Prerender = require('prerender-spa-plugin')
// const staticDir = path.join(__dirname, '..', 'dist')
// chain
// .plugin('prerender')
// .use(new Prerender({
// staticDir,
// routes: [ '/pages/index/index' ],
// postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
// }))
// }
}
}

86
package.json Normal file
View File

@ -0,0 +1,86 @@
{
"name": "taro-react-tailwind-vscode-template",
"version": "1.0.0",
"private": true,
"description": "",
"templateInfo": {
"name": "default",
"typescript": true,
"css": "sass"
},
"scripts": {
"build:weapp": "taro build --type weapp",
"build:swan": "taro build --type swan",
"build:alipay": "taro build --type alipay",
"build:tt": "taro build --type tt",
"build:h5": "taro build --type h5",
"build:rn": "taro build --type rn",
"build:qq": "taro build --type qq",
"build:jd": "taro build --type jd",
"build:quickapp": "taro build --type quickapp",
"dev:weapp": "npm run build:weapp -- --watch",
"dev:swan": "npm run build:swan -- --watch",
"dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch",
"dev:qq": "npm run build:qq -- --watch",
"dev:jd": "npm run build:jd -- --watch",
"dev:quickapp": "npm run build:quickapp -- --watch",
"open": "weapp open -p .",
"postinstall": "weapp-tw patch"
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"author": "",
"dependencies": {
"@babel/runtime": "^7.23.9",
"@tarojs/components": "3.6.23",
"@tarojs/helper": "3.6.23",
"@tarojs/plugin-framework-react": "3.6.23",
"@tarojs/plugin-platform-alipay": "3.6.23",
"@tarojs/plugin-platform-h5": "3.6.23",
"@tarojs/plugin-platform-jd": "3.6.23",
"@tarojs/plugin-platform-qq": "3.6.23",
"@tarojs/plugin-platform-swan": "3.6.23",
"@tarojs/plugin-platform-tt": "3.6.23",
"@tarojs/plugin-platform-weapp": "3.6.23",
"@tarojs/react": "3.6.23",
"@tarojs/runtime": "3.6.23",
"@tarojs/shared": "3.6.23",
"@tarojs/taro": "3.6.23",
"clsx": "^2.1.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@tarojs/cli": "3.6.23",
"@tarojs/webpack5-runner": "3.6.23",
"@types/node": "^20.11.16",
"@types/react": "^18.2.52",
"@types/webpack-env": "^1.18.4",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"babel-preset-taro": "3.6.23",
"eslint": "^8.56.0",
"eslint-config-taro": "3.6.23",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.2.0",
"postcss": "^8.4.33",
"postcss-rem-to-responsive-pixel": "^6.0.1",
"react-refresh": "^0.14.0",
"stylelint": "^16.2.1",
"tailwindcss": "^3.4.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"weapp-ide-cli": "^1.0.1",
"weapp-tailwindcss": "^3.0.9",
"webpack": "5.90.1"
}
}

6
postcss.config.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
// autoprefixer: {}
}
};

31
project.config.json Normal file
View File

@ -0,0 +1,31 @@
{
"miniprogramRoot": "dist/",
"projectname": "taro-react-tailwind-vscode-template",
"description": "",
"appid": "touristappid",
"setting": {
"urlCheck": true,
"es6": false,
"enhance": false,
"compileHotReLoad": false,
"postcss": false,
"minified": false,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"compileType": "miniprogram",
"libVersion": "2.30.3",
"srcMiniprogramRoot": "dist/",
"packOptions": {
"ignore": [],
"include": []
},
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}

View File

@ -0,0 +1,7 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "taro-react-tailwind-vscode-template",
"setting": {
"compileHotReLoad": false
}
}

9
project.tt.json Normal file
View File

@ -0,0 +1,9 @@
{
"miniprogramRoot": "./",
"projectname": "taro-react-tailwind-vscode-template",
"appid": "testAppId",
"setting": {
"es6": false,
"minified": false
}
}

12
src/app.config.ts Normal file
View File

@ -0,0 +1,12 @@
export default defineAppConfig({
pages: [
'pages/index/index',
'pages/setting/index'
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black'
}
})

3
src/app.scss Normal file
View File

@ -0,0 +1,3 @@
@import "tailwindcss/base";
@import 'tailwindcss/components';
@import "tailwindcss/utilities";

15
src/app.ts Normal file
View File

@ -0,0 +1,15 @@
import { PropsWithChildren } from 'react'
import { useLaunch } from '@tarojs/taro'
import './app.scss'
function App({ children }: PropsWithChildren) {
useLaunch(() => {
console.log('App launched.')
})
// children 是将要会渲染的页面
return children
}
export default App

17
src/index.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="format-detection" content="telephone=no,address=no">
<meta name="apple-mobile-web-app-status-bar-style" content="white">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title>taro-react-tailwind-vscode-template</title>
<script><%= htmlWebpackPlugin.options.script %></script>
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '首页'
})

View File

@ -0,0 +1,4 @@
.test {
@apply flex items-center justify-center h-[300px] w-[300px] rounded-[40px] bg-[#123456] bg-opacity-[0.54];
@apply text-[#ffffff] after:content-['@apply_classes'] #{!important};
}

50
src/pages/index/index.tsx Normal file
View File

@ -0,0 +1,50 @@
import { useState } from "react";
import { View } from "@tarojs/components";
import { clsx } from "clsx";
import "./index.scss";
import Taro from "@tarojs/taro";
const Index = () => {
const [flag, setFlag] = useState(true);
const className = clsx(
flag ? "bg-[#123456]" : "bg-[#654321]",
"text-white",
"after:content-['click_here_to_switch_bg_className']",
'p-[13.3333333px]',
'rounded-[10086px]'
);
const logoClass = clsx(
"bg-[url(https://pic1.zhimg.com/v2-3ee20468f54bbfefcd0027283b21aaa8_720w.jpg)] bg-[length:100%_100%] bg-no-repeat w-screen h-[41.54vw]"
);
return (
<>
<View className={logoClass}></View>
<View className='[&_.u-count-down\_\_text]:!text-sky-400'>
<View></View>
<View>
<View className="u-count-down__text text-[40px] text-center before:content-['taro-react-tailwind-vscode-template']"></View>
</View>
</View>
<View className='space-y-4 flex flex-col items-center'>
<View className="after:mx-auto after:text-center after:block after:content-['这是一个小程序taro_react_tailwindcss的模板'] after:text-lime-700"></View>
<View
className="rounded-lg p-1 bg-gray-100 dark:bg-zinc-800 h-20 w-40 after:text-xs after:content-['this_is_a_hover_block.have_a_try!']"
hoverClass='bg-red-500 dark:bg-green-500'
onClick={() => setFlag(false)}
></View>
<View
className={className}
onClick={() => {
Taro.redirectTo({
url: '/pages/setting/index'
})
}}
>TETT</View>
<View className='test'></View>
</View>
</>
);
};
export default Index;

View File

@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '设置'
})

View File

View File

@ -0,0 +1,21 @@
import { View } from "@tarojs/components";
import "./index.scss";
const Index = () => {
return (
<>
<View className="w-full p-2">
<View className="w-full text-center border p-2 rounded-md bg-red-300">Setting</View>
<View className="mt-2 border p-2 rounded-md">SSSWSS</View>
<View className="grid grid-cols-2 grid-rows-2 gap-2 py-2">
<View className="border bg-slate-300 h-20 p-2 rounded-md"></View>
<View className="border bg-slate-300 h-20 p-2 rounded-md"></View>
<View className="border bg-slate-300 h-20 p-2 rounded-md"></View>
<View className="border bg-slate-300 h-20 p-2 rounded-md"></View>
</View>
</View>
</>
);
};
export default Index;

12
tailwind.config.js Normal file
View File

@ -0,0 +1,12 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js,ts,jsx,tsx}"],
theme: {
extend: {}
},
plugins: [],
// v3 版本的 tailwindcss 有些不同
corePlugins: {
preflight: false
}
};

27
tsconfig.json Normal file
View File

@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"removeComments": false,
"preserveConstEnums": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"outDir": "lib",
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"sourceMap": true,
"baseUrl": ".",
"rootDir": ".",
"jsx": "react-jsx",
"allowJs": true,
"resolveJsonModule": true,
"typeRoots": [
"node_modules/@types"
]
},
"include": ["./src", "./types"],
"compileOnSave": false
}

19
types/global.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
/// <reference types="@tarojs/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'
}
}

11448
yarn.lock Normal file

File diff suppressed because it is too large Load Diff