Skip to content

Commit

Permalink
feat: init project
Browse files Browse the repository at this point in the history
  • Loading branch information
WindRunnerMax committed Feb 28, 2024
0 parents commit dc0b181
Show file tree
Hide file tree
Showing 155 changed files with 19,945 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config
TARO_APP_ID="wx387c0e87230e4cc9"
1 change: 1 addition & 0 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TARO_APP_ID="wx387c0e87230e4cc9"
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TARO_APP_ID="wx387c0e87230e4cc9"
55 changes: 55 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable import/no-commonjs */
module.exports = {
extends: ["taro/react", "eslint:recommended", "plugin:prettier/recommended"],
plugins: ["simple-import-sort"],
env: {
browser: true,
node: true,
commonjs: true,
es2021: true,
},
parserOptions: {
requireConfigFile: false,
ecmaVersion: 2020,
sourceType: "module",
},
overrides: [
{
files: ["*.ts"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["plugin:@typescript-eslint/recommended"],
},
{
files: ["*.tsx"],
parser: "@typescript-eslint/parser",
plugins: ["react", "react-hooks", "@typescript-eslint/eslint-plugin"],
extends: ["plugin:@typescript-eslint/recommended", "plugin:react-hooks/recommended"],
},
],
ignorePatterns: ["node_modules", "build", "dist", "coverage", "public"],
rules: {
// 分号
"semi": "error",
// 对象键值引号样式保持一致
"quote-props": ["error", "consistent-as-needed"],
// 箭头函数允许单参数不带括号
"arrow-parens": ["error", "as-needed"],
// no var
"no-var": "error",
// const
"prefer-const": "error",
// 允许console
"no-console": "off",
// 关闭每个函数都要显式声明返回值
"@typescript-eslint/explicit-module-boundary-types": "off",
// 关闭@ts-ignore检查
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/consistent-type-imports": "error",
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"import/first": "off",
"simple-import-sort/imports": "error",
},
};
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
dist/
deploy_versions/
.temp/
.rn_temp/
node_modules/
.DS_Store
.swc

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# log
*.log

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# production
build
dist

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmmirror.com/
18 changes: 18 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
"printWidth": 100, // 指定代码长度,超出换行
"tabWidth": 2, // tab 键的宽度
"useTabs": false, // 不使用tab
"semi": true, // 结尾加上分号
"singleQuote": false, // 使用单引号
"quoteProps": "preserve", // 不要求对象字面量属性是否使用引号包裹
"jsxSingleQuote": false, // jsx 语法中使用单引号
"trailingComma": "es5", // 确保对象的最后一个属性后有逗号
"bracketSpacing": true, // 大括号有空格 { name: 'rose' }
"jsxBracketSameLine": false, // 在多行JSX元素的最后一行追加 >
"arrowParens": "avoid", // 箭头函数,单个参数不强制添加括号
"requirePragma": false, // 是否严格按照文件顶部的特殊注释格式化代码
"insertPragma": false, // 是否在格式化的文件顶部插入Pragma标记,以表明该文件被prettier格式化过了
"proseWrap": "preserve", // 按照文件原样折行
"htmlWhitespaceSensitivity": "ignore", // html文件的空格敏感度,控制空格是否影响布局
"endOfLine": "lf", // 结尾是 \n \r \n\r auto
};
22 changes: 22 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
extends: ["stylelint-config-standard", "stylelint-config-sass-guidelines"],
ignoreFiles: [
"**/node_modules/**/*.*",
"**/dist/**/*.*",
"**/build/**/*.*",
"**/coverage/**/*.*",
"**/public/**/*.*",
],
rules: {
"no-descending-specificity": null,
"color-function-notation": null,
"alpha-value-notation": null,
"no-empty-source": null,
"selector-type-no-unknown": null,
"max-nesting-depth": 6,
"selector-max-compound-selectors": 6,
"selector-class-pattern": "^[a-z][a-zA-Z0-9_-]+$",
"selector-id-pattern": "^[a-z][a-zA-Z0-9_-]+$",
"scss/at-import-partial-extension-blacklist": null,
},
};
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cSpell.words": [
"sdust",
"SHST",
"swiper",
"tarojs",
"TSON"
]
}
14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable import/no-commonjs */
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
presets: [
[
"taro",
{
framework: "react",
ts: true,
},
],
],
};
30 changes: 30 additions & 0 deletions config/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { UserConfigExport } from "@tarojs/cli";

export default {
logger: {
quiet: false,
stats: true,
},
mini: {
webpackChain: chain => {
chain.merge({
plugin: {
install: {
plugin: require("terser-webpack-plugin"),
args: [
{
terserOptions: {
compress: true, // 默认使用terser压缩
// mangle: false,
keep_classnames: true, // 不改变class名称
keep_fnames: true, // 不改变函数名称
},
},
],
},
},
});
},
},
h5: {},
} satisfies UserConfigExport;
103 changes: 103 additions & 0 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { defineConfig, type UserConfigExport } from "@tarojs/cli";
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";

import devConfig from "./dev";
import prodConfig from "./prod";

// https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
export default defineConfig(async merge => {
const baseConfig: UserConfigExport = {
projectName: "SHST-UNI-NEXT",
date: "2023-11-17",
designWidth: 750,
deviceRatio: {
640: 2.34 / 2,
750: 1,
375: 2,
828: 1.81 / 2,
},
sourceRoot: "src",
outputRoot: "dist",
plugins: [],
defineConstants: {},
copy: {
patterns: [],
options: {},
},
framework: "react",
compiler: "webpack5",
cache: {
enable: true, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
},
mini: {
postcss: {
pxtransform: {
enable: false,
config: {},
},
url: {
enable: true,
config: {
limit: 1024, // 设定转换尺寸上限
},
},
cssModules: {
enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: "module", // 转换模式,取值为 global/module
generateScopedName: "[name]__[local]___[hash:base64:5]",
},
},
},
webpackChain(chain) {
chain.resolve.plugin("tsconfig-paths").use(TsconfigPathsPlugin);
},
miniCssExtractPluginOption: {
ignoreOrder: true,
},
},
h5: {
publicPath: "/",
staticDirectory: "static",
output: {
filename: "js/[name].[hash:8].js",
chunkFilename: "js/[name].[chunkhash:8].js",
},
miniCssExtractPluginOption: {
ignoreOrder: true,
filename: "css/[name].[hash].css",
chunkFilename: "css/[name].[chunkhash].css",
},
postcss: {
autoprefixer: {
enable: true,
config: {},
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: "module", // 转换模式,取值为 global/module
generateScopedName: "[name]__[local]___[hash:base64:5]",
},
},
},
webpackChain(chain) {
chain.resolve.plugin("tsconfig-paths").use(TsconfigPathsPlugin);
},
},
rn: {
appName: "taroDemo",
postcss: {
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
},
},
},
};
if (process.env.NODE_ENV === "development") {
// 本地开发构建配置(不混淆压缩)
return merge({}, baseConfig, devConfig);
}
// 生产构建配置(默认开启压缩混淆等)
return merge({}, baseConfig, prodConfig);
});
33 changes: 33 additions & 0 deletions config/prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { UserConfigExport } from "@tarojs/cli";

export default {
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') })
// }))
// }
},
} satisfies UserConfigExport;
8 changes: 8 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-commonjs */
const defineJestConfig = require("@tarojs/test-utils-react/dist/jest.js").default;

module.exports = defineJestConfig({
testEnvironment: "jsdom",
testMatch: ["<rootDir>/__tests__/?(*.)+(spec|test).[jt]s?(x)"],
});
Loading

0 comments on commit dc0b181

Please sign in to comment.