mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-09-09 23:03:03 +08:00
添加eslint
This commit is contained in:
parent
db1806e4eb
commit
2e4508dde7
BIN
dist/.DS_Store
vendored
BIN
dist/.DS_Store
vendored
Binary file not shown.
16
package.json
16
package.json
@ -23,21 +23,35 @@
|
||||
"vue-router": "^4.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.2",
|
||||
"@babel/eslint-parser": "^7.19.1",
|
||||
"@intlify/unplugin-vue-i18n": "^0.5.0",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/scrollreveal": "^0.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
||||
"@typescript-eslint/parser": "^5.42.1",
|
||||
"@vitejs/plugin-vue": "^3.0.0",
|
||||
"@vitejs/plugin-vue-jsx": "^2.0.0",
|
||||
"autoprefixer": "^10.4.8",
|
||||
"eslint": "^8.0.1",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-config-standard-with-typescript": "^23.0.0",
|
||||
"eslint-plugin-import": "^2.25.2",
|
||||
"eslint-plugin-n": "^15.0.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-promise": "^6.0.0",
|
||||
"eslint-plugin-react": "^7.31.10",
|
||||
"eslint-plugin-vue": "^9.7.0",
|
||||
"postcss": "^8.1.0",
|
||||
"postcss-pxtorem": "^6.0.0",
|
||||
"prettier": "^2.7.1",
|
||||
"svg-sprite-loader": "^6.0.11",
|
||||
"typescript": "^4.6.4",
|
||||
"typescript": "*",
|
||||
"unplugin-auto-import": "^0.11.0",
|
||||
"unplugin-vue-components": "^0.22.0",
|
||||
"vite": "^3.0.0",
|
||||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-eslint": "^1.8.1",
|
||||
"vite-plugin-inspect": "^0.6.0",
|
||||
"vite-plugin-svg-icons": "^2.0.1",
|
||||
"vite-svg-loader": "^3.4.0",
|
||||
|
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
BIN
src/components/.DS_Store
vendored
BIN
src/components/.DS_Store
vendored
Binary file not shown.
@ -1,16 +1,14 @@
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import messages from '@intlify/unplugin-vue-i18n/messages'
|
||||
|
||||
import { useGetCache } from '@use-utils/cache'
|
||||
import { getCache } from '@use-utils/cache'
|
||||
|
||||
import type { App } from 'vue'
|
||||
|
||||
export const setupI18n = (app: App<Element>) => {
|
||||
const i18n = createI18n({
|
||||
locale:
|
||||
useGetCache('languageType') !== 'no'
|
||||
? useGetCache('languageType')
|
||||
: 'zh-CN',
|
||||
getCache('languageType') !== 'no' ? getCache('languageType') : 'zh-CN',
|
||||
allowComposition: true, // you need to specify that!
|
||||
messages,
|
||||
})
|
||||
|
@ -3,7 +3,9 @@ import type { RouteRecordRaw } from 'vue-router'
|
||||
const route = import.meta.glob('./*.ts', { eager: true }) as IUnknownObjectKey
|
||||
|
||||
const routes = Object.keys(route).reduce((modules, modulePath) => {
|
||||
modules.push(route[modulePath].default)
|
||||
const _default = route[modulePath]
|
||||
|
||||
modules.push(_default as unknown as RouteRecordRaw)
|
||||
|
||||
return modules
|
||||
}, [] as RouteRecordRaw[])
|
||||
|
2
src/types/index.d.ts
vendored
2
src/types/index.d.ts
vendored
@ -4,7 +4,7 @@ import type CryptoJS from 'crypto-js'
|
||||
|
||||
export global {
|
||||
declare interface IUnknownObjectKey {
|
||||
[propName: string]: any
|
||||
[propName: string]: unknown
|
||||
}
|
||||
|
||||
declare type EventListenerOrEventListenerObject =
|
||||
|
@ -3,16 +3,19 @@
|
||||
* @param key 需要设置的key
|
||||
* @param value 需要缓存的值
|
||||
*/
|
||||
export const useSetCache = <T>(
|
||||
export const setCache = <T>(
|
||||
key: string,
|
||||
value: T,
|
||||
type: CacheType = 'sessionStorage',
|
||||
) => {
|
||||
const waitCacheValue = JSON.stringify(value)
|
||||
|
||||
type === 'localStorage'
|
||||
? window.localStorage.setItem(key, waitCacheValue)
|
||||
: window.sessionStorage.setItem(key, waitCacheValue)
|
||||
const func =
|
||||
type === 'localStorage'
|
||||
? window.localStorage.setItem
|
||||
: window.sessionStorage.setItem
|
||||
|
||||
func(key, waitCacheValue)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -21,11 +24,8 @@ export const useSetCache = <T>(
|
||||
*
|
||||
* @returns 获取缓存值
|
||||
*/
|
||||
export const useGetCache = (
|
||||
key: string,
|
||||
type: CacheType = 'sessionStorage',
|
||||
) => {
|
||||
let data =
|
||||
export const getCache = (key: string, type: CacheType = 'sessionStorage') => {
|
||||
const data =
|
||||
type === 'localStorage'
|
||||
? window.localStorage.getItem(key)
|
||||
: window.sessionStorage.getItem(key)
|
||||
@ -37,7 +37,7 @@ export const useGetCache = (
|
||||
*
|
||||
* @param key 需要删除的缓存值key
|
||||
*/
|
||||
export const useRemoveCache = (
|
||||
export const removeCache = (
|
||||
key: string | 'all' | 'all-sessionStorage' | 'all-localStorage',
|
||||
type: CacheType = 'sessionStorage',
|
||||
) => {
|
||||
@ -49,8 +49,11 @@ export const useRemoveCache = (
|
||||
} else if (key === 'all-localStorage') {
|
||||
window.localStorage.clear()
|
||||
} else {
|
||||
type === 'localStorage'
|
||||
? window.localStorage.removeItem(key)
|
||||
: window.sessionStorage.removeItem(key)
|
||||
const func =
|
||||
type === 'localStorage'
|
||||
? window.localStorage.removeItem
|
||||
: window.sessionStorage.removeItem
|
||||
|
||||
func(key)
|
||||
}
|
||||
}
|
||||
|
@ -135,10 +135,14 @@ export const addStyle = (
|
||||
el.style[item] = styles[item]
|
||||
})
|
||||
} else if (useValidteValueType(styles, 'String')) {
|
||||
;(styles as string).split(';').forEach((item) => {
|
||||
const _styles = styles as string
|
||||
|
||||
_styles.split(';').forEach((item) => {
|
||||
const [_k, _v] = item.split(':')
|
||||
|
||||
_k && _v && (el.style[_k.trim()] = _v.trim())
|
||||
if (_k && _v) {
|
||||
el.style[_k.trim()] = _v.trim()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -191,20 +191,20 @@ export const useViteServerPlugin = (options?: ServerOptions) => {
|
||||
}
|
||||
|
||||
export const useEnvBuildOutput = (mode: string) => {
|
||||
let buildOptions = {
|
||||
const buildOptions: BuildOptions = {
|
||||
outDir: 'dist/test-dist',
|
||||
sourcemap: false,
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true, // 打包后移除console
|
||||
drop_debugger: true, // 打包后移除debugger
|
||||
drop_console: true, // 打包后移除 `console`
|
||||
drop_debugger: true, // 打包后移除 `debugger`
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case 'test':
|
||||
buildOptions = {
|
||||
Object.assign(buildOptions, {
|
||||
outDir: 'dist/test-dist',
|
||||
sourcemap: true,
|
||||
terserOptions: {
|
||||
@ -213,11 +213,12 @@ export const useEnvBuildOutput = (mode: string) => {
|
||||
drop_debugger: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
break
|
||||
|
||||
case 'development':
|
||||
buildOptions = {
|
||||
Object.assign(buildOptions, {
|
||||
outDir: 'dist/development-dist',
|
||||
sourcemap: true,
|
||||
terserOptions: {
|
||||
@ -226,11 +227,12 @@ export const useEnvBuildOutput = (mode: string) => {
|
||||
drop_debugger: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
break
|
||||
|
||||
case 'production':
|
||||
buildOptions = {
|
||||
Object.assign(buildOptions, {
|
||||
outDir: 'dist/production-dist',
|
||||
sourcemap: false,
|
||||
terserOptions: {
|
||||
@ -239,7 +241,10 @@ export const useEnvBuildOutput = (mode: string) => {
|
||||
drop_debugger: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ export interface VitePluginCompression {
|
||||
/**
|
||||
* Compression Options
|
||||
*/
|
||||
compressionOptions?: {}
|
||||
compressionOptions?: object
|
||||
/**
|
||||
* Delete the corresponding source file after compressing the file
|
||||
* @default: false
|
||||
|
@ -17,6 +17,7 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
|
||||
import ViteInspect from 'vite-plugin-inspect'
|
||||
import viteSvgLoader from 'vite-svg-loader'
|
||||
import viteEslintPlugin from 'vite-plugin-eslint'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
@ -40,6 +41,17 @@ export default defineConfig(async ({ mode }) => {
|
||||
defaultImport: 'component', // 默认以 `componetn` 形式导入 `svg`
|
||||
}),
|
||||
useSVGIcon(),
|
||||
viteEslintPlugin,
|
||||
{
|
||||
include: [
|
||||
'src/**/*.ts',
|
||||
'src/**/*.tsx',
|
||||
'src/**/*.vue',
|
||||
'src/*.ts',
|
||||
'src/*.tsx',
|
||||
'src/*.vue',
|
||||
],
|
||||
},
|
||||
],
|
||||
optimizeDeps: {
|
||||
include: ['vue', 'vue-router', 'pinia', 'vue-i18n', '@vueuse/core'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user