Skip to content

Commit

Permalink
chore(项目初始化): 项目初始化
Browse files Browse the repository at this point in the history
项目初始化
  • Loading branch information
jianfengtheboy committed Jul 30, 2024
1 parent b111a31 commit c47e234
Show file tree
Hide file tree
Showing 69 changed files with 16,916 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
103 changes: 103 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"extends": ["taro/vue3"],
"rules": {
// 关闭组件命名规则
"vue/multi-word-component-names": "off",
// 强制使用一致的缩进
"indent": [2, 2],
// 要求使用 === 和 !==
"eqeqeq": [2, "always"],
// 要求或禁止使用分号代替 ASI
"semi": "off",
// 强制使用一致的反勾号、双引号或单引号
"quotes": "off",
"no-var": "error",
"prettier/prettier": "off",
// 禁止出现console
"no-console": "off",
// 禁用debugger
"no-debugger": "warn",
// 禁止出现重复的 case 标签
"no-duplicate-case": "off",
// 禁止出现空语句块
"no-empty": "warn",
// 禁止不必要的括号
"no-extra-parens": "off",
// 禁止对 function 声明重新赋值
"no-func-assign": "warn",
// 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
"no-unreachable": "warn",
// 强制所有控制语句使用一致的括号风格
"curly": "warn",
// 要求 switch 语句中有 default 分支
"default-case": "warn",
// 强制尽可能地使用点号
"dot-notation": "warn",
// 禁止 if 语句中 return 语句之后有 else 块
"no-else-return": "warn",
// 禁止出现空函数
"no-empty-function": "off",
// 禁用不必要的嵌套块
"no-lone-blocks": "warn",
// 禁止使用多个空格
"no-multi-spaces": "warn",
// 禁止多次声明同一变量
"no-redeclare": "warn",
// 禁止在 return 语句中使用赋值语句
"no-return-assign": "warn",
// 禁用不必要的 return await
"no-return-await": "off",
// 禁止自我赋值
"no-self-assign": "warn",
// 禁止自身比较
"no-self-compare": "warn",
// 禁止不必要的 catch 子句
"no-useless-catch": "warn",
// 禁止多余的 return 语句
"no-useless-return": "warn",
// 禁止变量声明与外层作用域的变量同名
"no-shadow": "off",
// 允许delete变量
"no-delete-var": "off",
// 强制数组方括号中使用一致的空格
"array-bracket-spacing": "warn",
// 强制在代码块中使用一致的大括号风格
"brace-style": "warn",
// 强制使用骆驼拼写法命名约定
"camelcase": "off",
// 强制可嵌套的块的最大深度4
"max-depth": "warn",
// 强制最大行数 300
// "max-lines": ["warn", { "max": 1200 }],
// 强制函数最大代码行数 50
// 'max-lines-per-function': ['warn', { max: 70 }],
// 强制函数块最多允许的的语句数量20
"max-statements": ["warn", 100],
// 强制回调函数最大嵌套深度
"max-nested-callbacks": ["warn", 3],
// 强制函数定义中最多允许的参数数量
"max-params": ["warn", 10],
// 要求方法链中每个调用都有一个换行符
"newline-per-chained-call": ["off", { "ignoreChainWithDepth": 3 }],
// 禁止 if 作为唯一的语句出现在 else 语句中
"no-lonely-if": "warn",
// 禁止空格和 tab 的混合缩进
"no-mixed-spaces-and-tabs": "warn",
// 禁止出现多行空行
"no-multiple-empty-lines": "warn",
// 强制在块之前使用一致的空格
"space-before-blocks": "warn",
// 要求操作符周围有空格
"space-infix-ops": "warn",
// 强制在一元操作符前后使用一致的空格
"space-unary-ops": "warn",
// 强制在注释中 // 或 /* 使用一致的空格
// "spaced-comment": "warn",
// 强制在 switch 的冒号左右有空格
"switch-colon-spacing": "warn",
// 强制箭头函数的箭头前后使用一致的空格
"arrow-spacing": "warn",
"prefer-const": "warn"
}
}

13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
dist/
deploy_versions/
.temp/
.rn_temp/
node_modules/
.DS_Store
.swc
package-lock.json
components.d.ts
npm-debug.log*
yarn-debug.log*
yarn-error.log*
**/*.log
8 changes: 8 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
presets: [
['taro', {
framework: 'vue3',
ts: true
}]
]
}
12 changes: 12 additions & 0 deletions config/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
env: {
NODE_ENV: '"development"',
// 开发环境
HTTP_URL: '"https://cloud.xxxx.com/development-api"'
// 测试环境
// HTTP_URL: '"https://cloud.xxxx.com/test-api"'
},
defineConstants: {},
mini: {},
h5: {}
}
174 changes: 174 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import Components from 'unplugin-vue-components/webpack'
const path = require('path')

const NutUIResolver = () => {
return (name) => {
if (name.startsWith('Nut')) {
const partialName = name.slice(3)
return {
name: partialName,
from: '@nutui/nutui-taro',
sideEffects: `@nutui/nutui-taro/dist/packages/${partialName.toLowerCase()}/style`,
}
}
}
}

const config = {
// 项目名称
projectName: 'weapp-app-ui',
// 项目创建日期
date: '2023-6-6',
// 设计稿尺寸,配置 NutUI 375 尺寸
designWidth (input) {
if (input?.file?.replace(/\\+/g, '/').indexOf('@nutui') > -1) {
return 375
}
return 750
},
// 设计稿尺寸换算规则
deviceRatio: {
640: 2.34 / 2,
750: 1,
828: 1.81 / 2,
375: 2 / 1
},
// 项目源码目录
sourceRoot: 'src',
// 项目产出目录,分端打包配置
outputRoot: `dist/${process.env.TARO_ENV}`,
// Taro 插件配置
plugins: ['@tarojs/plugin-html', 'taro-plugin-pinia'],
// 全局变量设置
defineConstants: {},
// 文件 copy 配置
copy: {
patterns: [],
options: {}
},
// 配置目录别名
alias: {
'@' : path.resolve(__dirname, '..', 'src')
},
// 框架,react,nerv,vue, vue3 等
framework: 'vue3',
compiler: {
type: 'webpack5',
prebundle: { enable: false }
},
// Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
cache: {
enable: false
},
// sass文件导入
sass:{
data: `@import "@nutui/nutui-taro/dist/styles/variables.scss";`
},
// 小程序
mini: {
webpackChain(chain) {
chain.plugin('unplugin-vue-components').use(Components({
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
resolvers: [NutUIResolver({ taro: true })]
}))
},
postcss: {
autoprefixer: {
enable: true,
},
pxtransform: {
enable: true,
config: {
onePxTransform: true,
unitPrecision: 5,
propList: ['*'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 0
}
},
// 小程序端样式引用本地资源内联配置
url: {
enable: true,
config: {
limit: 1024 // 设定转换尺寸上限
}
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
},
// mini-css-extract-plugin 的附加配置
miniCssExtractPluginOption: {
ignoreOrder: true
},
optimizeMainPackage: {
enable: true
}
},
// h5
h5: {
webpackChain(chain) {
chain.plugin('unplugin-vue-components').use(Components({
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
resolvers: [NutUIResolver({ taro: true })]
}))
},
publicPath: '/',
staticDirectory: 'static',
esnextModules: ['nutui-taro', 'icons-vue-taro'],
postcss: {
autoprefixer: {
enable: true,
config: {}
},
pxtransform: {
enable: true,
config: {
onePxTransform: true,
unitPrecision: 5,
propList: ['*'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 0,
baseFontSize: 20,
maxRootSize: 40,
minRootSize: 20
}
},
cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
},
devServer: {
port: 9000,
host: '0.0.0.0',
proxy: {
'/dev-api': {
target: 'https://cloud.xxxx.com/development-api',
changeOrigin: true,
pathRewrite: {
'^/dev-api': ''
}
}
}
}
}
}

module.exports = function (merge) {
if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev'))
}
return merge({}, config, require('./prod'))
}
37 changes: 37 additions & 0 deletions config/prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
env: {
NODE_ENV: '"production"',
HTTP_URL: '"https://cloud.xxxx.com/prod-api"'
},
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') })
// }))
// }
}
}
Loading

0 comments on commit c47e234

Please sign in to comment.