mirror of
https://gitee.com/h_mo/uniapp-vue3-vite-ts-template
synced 2025-04-06 03:58:03 +08:00
feat-eslint + prettier代码规范
This commit is contained in:
parent
a95275e3ad
commit
b7ae8b7349
20
.eslintignore
Normal file
20
.eslintignore
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# eslint 忽略检查 (根据项目需要自行添加)
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
.hbuilderx
|
||||||
|
src/manifest.json
|
||||||
|
src/pages.json
|
||||||
|
*.sh
|
||||||
|
node_modules
|
||||||
|
*.md
|
||||||
|
*.woff
|
||||||
|
*.ttf
|
||||||
|
*.yaml
|
||||||
|
dist
|
||||||
|
/public
|
||||||
|
/docs
|
||||||
|
.husky
|
||||||
|
.local
|
||||||
|
/bin
|
111
.eslintrc.js
Normal file
111
.eslintrc.js
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
es2021: true,
|
||||||
|
},
|
||||||
|
parser: 'vue-eslint-parser',
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:vue/essential',
|
||||||
|
'plugin:vue/vue3-recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'prettier',
|
||||||
|
],
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
'import/resolver': {
|
||||||
|
alias: {
|
||||||
|
map: [['@', './src']],
|
||||||
|
extensions: ['.ts', '.js', '.jsx', '.json', '.vue'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: ['vue', '@typescript-eslint', 'prettier'],
|
||||||
|
rules: {
|
||||||
|
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||||
|
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||||
|
'no-var': 'error',
|
||||||
|
'prettier/prettier': 'error',
|
||||||
|
'vue/no-multiple-template-root': 'off',
|
||||||
|
'no-mutating-props': 'off',
|
||||||
|
'vue/no-v-html': 'off',
|
||||||
|
// @fixable 必须使用单引号,禁止使用双引号
|
||||||
|
quotes: [
|
||||||
|
'error',
|
||||||
|
'single',
|
||||||
|
{
|
||||||
|
avoidEscape: true,
|
||||||
|
allowTemplateLiterals: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// 结尾必须有分号;
|
||||||
|
semi: [
|
||||||
|
'error',
|
||||||
|
'always',
|
||||||
|
{
|
||||||
|
omitLastInOneLineBlock: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'vue/script-setup-uses-vars': 'error',
|
||||||
|
'@typescript-eslint/ban-ts-ignore': 'off',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
|
'@typescript-eslint/no-empty-function': 'off',
|
||||||
|
'vue/custom-event-name-casing': 'off',
|
||||||
|
'no-use-before-define': 'off',
|
||||||
|
'@typescript-eslint/no-use-before-define': 'off',
|
||||||
|
'@typescript-eslint/ban-ts-comment': 'off',
|
||||||
|
'@typescript-eslint/ban-types': 'off',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
|
'@typescript-eslint/no-unused-vars': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
argsIgnorePattern: '^_',
|
||||||
|
varsIgnorePattern: '^_',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'no-unused-vars': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
argsIgnorePattern: '^_',
|
||||||
|
varsIgnorePattern: '^_',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'space-before-function-paren': 'off',
|
||||||
|
|
||||||
|
'vue/attributes-order': 'off',
|
||||||
|
'vue/v-on-event-hyphenation': 'off',
|
||||||
|
'vue/multi-word-component-names': 'off',
|
||||||
|
'vue/one-component-per-file': 'off',
|
||||||
|
'vue/html-closing-bracket-newline': 'off',
|
||||||
|
'vue/max-attributes-per-line': 'off',
|
||||||
|
'vue/multiline-html-element-content-newline': 'off',
|
||||||
|
'vue/singleline-html-element-content-newline': 'off',
|
||||||
|
'vue/attribute-hyphenation': 'off',
|
||||||
|
'vue/require-default-prop': 'off',
|
||||||
|
'vue/html-self-closing': [
|
||||||
|
'error',
|
||||||
|
{
|
||||||
|
html: {
|
||||||
|
void: 'always',
|
||||||
|
normal: 'never',
|
||||||
|
component: 'always',
|
||||||
|
},
|
||||||
|
svg: 'always',
|
||||||
|
math: 'always',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
globals: {
|
||||||
|
defineProps: 'readonly',
|
||||||
|
defineEmits: 'readonly',
|
||||||
|
defineExpose: 'readonly',
|
||||||
|
withDefaults: 'readonly',
|
||||||
|
},
|
||||||
|
};
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/dist/
|
/dist/
|
||||||
/.idea/
|
/.idea/
|
||||||
/.hbuilderx/
|
/.hbuilderx/
|
||||||
|
/.eslintcache
|
||||||
|
20
.prettierignore
Normal file
20
.prettierignore
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# 忽略格式化文件 (根据项目需要自行添加)
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
.hbuilderx
|
||||||
|
src/manifest.json
|
||||||
|
src/pages.json
|
||||||
|
*.sh
|
||||||
|
node_modules
|
||||||
|
*.md
|
||||||
|
*.woff
|
||||||
|
*.ttf
|
||||||
|
*.yaml
|
||||||
|
dist
|
||||||
|
/public
|
||||||
|
/docs
|
||||||
|
.husky
|
||||||
|
.local
|
||||||
|
/bin
|
10
.prettierrc.js
Normal file
10
.prettierrc.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module.exports = {
|
||||||
|
printWidth: 100,
|
||||||
|
semi: true,
|
||||||
|
vueIndentScriptAndStyle: true,
|
||||||
|
singleQuote: true,
|
||||||
|
trailingComma: 'all',
|
||||||
|
proseWrap: 'never',
|
||||||
|
htmlWhitespaceSensitivity: 'strict',
|
||||||
|
endOfLine: 'auto',
|
||||||
|
};
|
10
index.html
10
index.html
@ -3,11 +3,15 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<script>
|
<script>
|
||||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
var coverSupport =
|
||||||
CSS.supports('top: constant(a)'))
|
'CSS' in window &&
|
||||||
|
typeof CSS.supports === 'function' &&
|
||||||
|
(CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'));
|
||||||
document.write(
|
document.write(
|
||||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
(coverSupport ? ', viewport-fit=cover' : '') +
|
||||||
|
'" />',
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
<title></title>
|
<title></title>
|
||||||
<!--preload-links-->
|
<!--preload-links-->
|
||||||
|
12
package.json
12
package.json
@ -29,7 +29,9 @@
|
|||||||
"build:mp-weixin": "uni build -p mp-weixin",
|
"build:mp-weixin": "uni build -p mp-weixin",
|
||||||
"build:quickapp-webview": "uni build -p quickapp-webview",
|
"build:quickapp-webview": "uni build -p quickapp-webview",
|
||||||
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
||||||
"build:quickapp-webview-union": "uni build -p quickapp-webview-union"
|
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
|
||||||
|
"lint": "eslint --cache --max-warnings 0 \"src/**/*.{vue,ts}\" --fix",
|
||||||
|
"prettier": "prettier --write \"src/**/*.{js,ts,json,css,scss,vue}\""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dcloudio/uni-app": "3.0.0-alpha-3040820220424001",
|
"@dcloudio/uni-app": "3.0.0-alpha-3040820220424001",
|
||||||
@ -54,9 +56,17 @@
|
|||||||
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3040820220424001",
|
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3040820220424001",
|
||||||
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3040820220424001",
|
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-3040820220424001",
|
||||||
"@types/node": "^17.0.38",
|
"@types/node": "^17.0.38",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
||||||
|
"@typescript-eslint/parser": "^5.27.0",
|
||||||
|
"eslint": "^8.16.0",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
|
"eslint-plugin-vue": "^9.1.0",
|
||||||
|
"prettier": "^2.6.2",
|
||||||
"sass": "^1.52.1",
|
"sass": "^1.52.1",
|
||||||
"typescript": "^4.6.3",
|
"typescript": "^4.6.3",
|
||||||
"vite": "^2.9.6",
|
"vite": "^2.9.6",
|
||||||
|
"vite-plugin-eslint": "^1.6.1",
|
||||||
"vite-plugin-windicss": "^1.8.4"
|
"vite-plugin-windicss": "^1.8.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4028
pnpm-lock.yaml
generated
4028
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
13
src/App.vue
13
src/App.vue
@ -1,22 +1,23 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {onLaunch, onShow, onHide} from "@dcloudio/uni-app";
|
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
|
||||||
|
|
||||||
onLaunch(() => {
|
onLaunch(() => {
|
||||||
console.log("App Launch");
|
console.log('App Launch');
|
||||||
});
|
});
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
console.log("App Show");
|
console.log('App Show');
|
||||||
});
|
});
|
||||||
onHide(() => {
|
onHide(() => {
|
||||||
console.log("App Hide");
|
console.log('App Hide');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
:not(not), ::before, ::after {
|
:not(not),
|
||||||
|
::before,
|
||||||
|
::after {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* 隐藏scroll-view的滚动条 */
|
/* 隐藏scroll-view的滚动条 */
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
<template>
|
<template>Test Component-----{{ msg }}</template>
|
||||||
Test Component
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
@ -8,7 +6,11 @@ import {defineComponent} from 'vue';
|
|||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'Test',
|
name: 'Test',
|
||||||
setup() {
|
setup() {
|
||||||
}
|
const msg = 'sdfa';
|
||||||
|
return {
|
||||||
|
msg,
|
||||||
|
};
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang="scss"></style>
|
<style scoped lang="scss"></style>
|
||||||
|
6
src/env.d.ts
vendored
6
src/env.d.ts
vendored
@ -1,8 +1,8 @@
|
|||||||
// / <reference types="vite/client" />
|
// / <reference types="vite/client" />
|
||||||
|
|
||||||
declare module '*.vue' {
|
declare module '*.vue' {
|
||||||
import { DefineComponent } from 'vue'
|
import { DefineComponent } from 'vue';
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
||||||
const component: DefineComponent<{}, {}, any>
|
const component: DefineComponent<{}, {}, any>;
|
||||||
export default component
|
export default component;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createSSRApp } from "vue";
|
import { createSSRApp } from 'vue';
|
||||||
import App from "./App.vue";
|
import App from './App.vue';
|
||||||
import 'virtual:windi.css';
|
import 'virtual:windi.css';
|
||||||
export function createApp() {
|
export function createApp() {
|
||||||
const app = createSSRApp(App);
|
const app = createSSRApp(App);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
|
"pages": [
|
||||||
|
//pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
|
||||||
{
|
{
|
||||||
"path": "pages/index/index",
|
"path": "pages/index/index",
|
||||||
"style": {
|
"style": {
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue';
|
||||||
import Test from "@/components/test/Test.vue";
|
import Test from '@/components/test/Test.vue';
|
||||||
const title = ref('Hello')
|
const title = ref('Hello');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
@ -68,9 +68,9 @@ $uni-spacing-col-lg: 24rpx;
|
|||||||
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
|
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
|
||||||
|
|
||||||
/* 文章场景相关 */
|
/* 文章场景相关 */
|
||||||
$uni-color-title: #2C405A; // 文章标题颜色
|
$uni-color-title: #2c405a; // 文章标题颜色
|
||||||
$uni-font-size-title: 40rpx;
|
$uni-font-size-title: 40rpx;
|
||||||
$uni-color-subtitle: #555555; // 二级标题颜色
|
$uni-color-subtitle: #555555; // 二级标题颜色
|
||||||
$uni-font-size-subtitle: 36rpx;
|
$uni-font-size-subtitle: 36rpx;
|
||||||
$uni-color-paragraph: #3F536E; // 文章段落颜色
|
$uni-color-paragraph: #3f536e; // 文章段落颜色
|
||||||
$uni-font-size-paragraph: 30rpx;
|
$uni-font-size-paragraph: 30rpx;
|
@ -1,11 +1,13 @@
|
|||||||
import {defineConfig} from "vite";
|
import { defineConfig } from 'vite';
|
||||||
import uni from "@dcloudio/vite-plugin-uni";
|
import uni from '@dcloudio/vite-plugin-uni';
|
||||||
|
import eslintPlugin from 'vite-plugin-eslint';
|
||||||
import windicss from 'vite-plugin-windicss';
|
import windicss from 'vite-plugin-windicss';
|
||||||
import MiniProgramTailwind from '@dcasia/mini-program-tailwind-webpack-plugin/rollup';
|
import MiniProgramTailwind from '@dcasia/mini-program-tailwind-webpack-plugin/rollup';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
base: './',
|
||||||
plugins: [
|
plugins: [
|
||||||
uni(),
|
uni(),
|
||||||
windicss(),
|
windicss(),
|
||||||
@ -13,7 +15,12 @@ export default defineConfig({
|
|||||||
// 是否开启自动转换至 rpx 单位值的功能
|
// 是否开启自动转换至 rpx 单位值的功能
|
||||||
enableRpx: true,
|
enableRpx: true,
|
||||||
// 设计稿的像素宽度值,该尺寸会影响 rpx 转换过程中的计算比率
|
// 设计稿的像素宽度值,该尺寸会影响 rpx 转换过程中的计算比率
|
||||||
designWidth: 350
|
designWidth: 350,
|
||||||
|
}),
|
||||||
|
eslintPlugin({
|
||||||
|
include: ['src/**/*.js', 'src/**/*.vue', 'src/**/*.ts'],
|
||||||
|
exclude: ['./node_modules/**'],
|
||||||
|
cache: false,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
@ -9,13 +9,13 @@ export default defineConfig({
|
|||||||
prefixer: false,
|
prefixer: false,
|
||||||
extract: {
|
extract: {
|
||||||
// 忽略部分文件夹
|
// 忽略部分文件夹
|
||||||
exclude: ['node_modules', '.git', 'dist', '.idea', '.vscode']
|
exclude: ['node_modules', '.git', 'dist', '.idea', '.vscode'],
|
||||||
},
|
},
|
||||||
corePlugins: {
|
corePlugins: {
|
||||||
// 禁用掉在小程序环境中不可能用到的 plugins
|
// 禁用掉在小程序环境中不可能用到的 plugins
|
||||||
container: false
|
container: false,
|
||||||
},
|
},
|
||||||
alias: {},
|
alias: {},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
variants: {}
|
variants: {},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user