v3.0.2发布,新增文档,优化一些结构

This commit is contained in:
chuan_wuhao 2022-12-29 14:58:28 +08:00
parent 161b133b9a
commit 4d84d7a553
11 changed files with 203 additions and 148 deletions

View File

@ -8,4 +8,5 @@ public
yarn.*
vite-env.*
.prettierrc.*
.eslintrc
.eslintrc
visualizer.*

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ dist-ssr
dist
dist/
*.local
visualizer.*
# Editor directories and files
.vscode

80
cfg.ts Normal file
View File

@ -0,0 +1,80 @@
import path from 'node:path'
import { HTMLTitlePlugin, buildOptions } from './vite-plugin/index'
import type { ServerOptions, BuildOptions, AliasOptions } from 'vite'
export interface HTMLTitle {
name: string
transformIndexHtml: (title: string) => string
}
export interface Config {
server: ServerOptions
buildOptions: (mode: string) => BuildOptions
alias: AliasOptions
title: HTMLTitle
}
const config: Config = {
/**
*
*
*/
title: HTMLTitlePlugin('ray template'),
/**
*
* HMR
*/
server: {
host: '0.0.0.0',
port: 9527,
open: false,
https: false,
strictPort: false,
fs: {
strict: false,
allow: [],
},
proxy: {
'/api': {
target: 'url',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
/**
*
*
*/
buildOptions: buildOptions,
/**
*
*
* - `@`: `src`
* - `@use-utils`: `src/utils`
* - `@use-api`: `src/axios/api`
* - `@use-images`: `src/assets/images`
*/
alias: [
{
find: '@',
replacement: path.resolve(__dirname, './src'),
},
{
find: '@use-utils',
replacement: path.resolve(__dirname, './src/utils'),
},
{
find: '@use-api',
replacement: path.resolve(__dirname, './src/axios/api'),
},
{
find: '@use-images',
replacement: path.resolve(__dirname, './src/assets/images'),
},
],
}
export default config

View File

@ -8,7 +8,8 @@
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"test": "vue-tsc --noEmit && vite build --mode test",
"dev-build": "vue-tsc --noEmit && vite build --mode development"
"dev-build": "vue-tsc --noEmit && vite build --mode development",
"report": "vue-tsc --noEmit && vite build"
},
"dependencies": {
"@vueuse/core": "^9.1.0",
@ -54,6 +55,7 @@
"postcss": "^8.1.0",
"postcss-pxtorem": "^6.0.0",
"prettier": "^2.7.1",
"rollup-plugin-visualizer": "^5.8.3",
"svg-sprite-loader": "^6.0.11",
"typescript": "*",
"unplugin-auto-import": "^0.11.0",

View File

@ -1,4 +1,4 @@
import useRequest from '../index'
import useRequest from '@/axios/index'
/**
*

View File

@ -24,6 +24,7 @@ import { cloneDeep } from 'lodash-es'
import { on, off } from '@/utils/element'
import type { PropType } from 'vue'
import type {} from 'echarts'
export type AutoResize =
| boolean
@ -150,6 +151,16 @@ const RayChart = defineComponent({
type: Boolean,
default: false,
},
use: {
/**
*
* `echarts`
*
* , , `any`
*/
type: Array,
default: () => [],
},
},
setup(props) {
const settingStore = useSetting()
@ -194,6 +205,15 @@ const RayChart = defineComponent({
echarts.use([LabelLayout, UniversalTransition]) // 注册布局, 过度效果
echarts.use([props.canvasRender ? CanvasRenderer : SVGRenderer]) // 注册渲染器
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
echarts.use(props.use as any[])
} catch (e) {
console.error(
'Error: wrong property and method passed in extend attribute',
)
}
}
/**

View File

@ -12,13 +12,15 @@
</router-view>
</template>
<script lang="ts" setup>
import type { PropType } from 'vue'
defineProps({
transitionPropName: {
type: String,
default: 'fade',
},
transitionMode: {
type: String,
type: String as PropType<'default' | 'out-in' | 'in-out' | undefined>,
default: 'out-in',
},
transitionAppear: {

View File

@ -202,8 +202,8 @@ const Echart = defineComponent({
<div class="echart">
<NCard title="RayChart组件使用">
使, ,
使, .
, ,
使, echarts , 使 use
. , ,
</NCard>
<NCard title="基础使用">

View File

@ -9,6 +9,6 @@
"vite.config.ts",
"vite-plugin/index.ts",
"vite-plugin/type.ts",
"package.ts"
"cfg.ts"
]
}

View File

@ -29,46 +29,6 @@ export const useSVGIcon = (options?: ViteSvgIconsPlugin) => {
return createSvgIconsPlugin(Object.assign(defaultOptions, options))
}
/**
*
* @param options
*
* 使
* 使, `vite-plugin`
* , `tsconfig.json` `paths`
*/
export const useAliasOptions = (
options?: { find: string; replacement: string }[],
) => {
const alias = [
{
find: '@',
replacement: path.resolve(__dirname, '../src'),
},
{
find: '@use-utils',
replacement: path.resolve(__dirname, '../src/utils'),
},
{
find: '@use-api',
replacement: path.resolve(__dirname, '../src/axios/api'),
},
{
find: '@use-images',
replacement: path.resolve(__dirname, '../src/assets/images'),
},
]
options?.forEach((curr) =>
alias.push({
find: curr.find,
replacement: path.resolve(__dirname, curr.replacement),
}),
)
return alias
}
/**
*
* @param imp
@ -133,7 +93,7 @@ export const useVueI18nPlugin = () =>
*
* @param title title
*/
export const useHTMLTitlePlugin = (title = 'ray template') => {
export const HTMLTitlePlugin = (title = 'ray template') => {
return {
name: 'html-transform',
transformIndexHtml: (html: string) => {
@ -142,6 +102,76 @@ export const useHTMLTitlePlugin = (title = 'ray template') => {
}
}
/**
*
* @param mode
*
* @remark
*/
export const buildOptions = (mode: string): BuildOptions => {
switch (mode) {
case 'test':
return {
outDir: 'dist/test-dist',
sourcemap: true,
terserOptions: {
compress: {
drop_console: false,
drop_debugger: false,
},
},
}
case 'development':
return {
outDir: 'dist/development-dist',
sourcemap: true,
terserOptions: {
compress: {
drop_console: false,
drop_debugger: false,
},
},
}
case 'production':
return {
outDir: 'dist/production-dist',
sourcemap: false,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
}
case 'report':
return {
outDir: 'dist/report-dist',
sourcemap: true,
terserOptions: {
compress: {
drop_console: false,
drop_debugger: false,
},
},
}
default:
return {
outDir: 'dist/test-dist',
sourcemap: false,
terserOptions: {
compress: {
drop_console: true, // 打包后移除 `console`
drop_debugger: true, // 打包后移除 `debugger`
},
},
}
}
}
/**
*
* @param options
@ -164,93 +194,3 @@ export const useViteBuildPlugin = (options?: BuildOptions) => {
return Object.assign(defaultPlugin, options)
}
/**
*
* @param options
*/
export const useViteServerPlugin = (options?: ServerOptions) => {
const server: ServerOptions = {
host: '0.0.0.0',
port: 9527,
open: false,
https: false,
strictPort: false,
fs: {
strict: false,
allow: [],
},
proxy: {
'/api': {
target: 'url',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
}
return Object.assign(server, options)
}
export const useEnvBuildOutput = (mode: string) => {
const buildOptions: BuildOptions = {
outDir: 'dist/test-dist',
sourcemap: false,
terserOptions: {
compress: {
drop_console: true, // 打包后移除 `console`
drop_debugger: true, // 打包后移除 `debugger`
},
},
}
switch (mode) {
case 'test':
Object.assign(buildOptions, {
outDir: 'dist/test-dist',
sourcemap: true,
terserOptions: {
compress: {
drop_console: false,
drop_debugger: false,
},
},
})
break
case 'development':
Object.assign(buildOptions, {
outDir: 'dist/development-dist',
sourcemap: true,
terserOptions: {
compress: {
drop_console: false,
drop_debugger: false,
},
},
})
break
case 'production':
Object.assign(buildOptions, {
outDir: 'dist/production-dist',
sourcemap: false,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
})
break
default:
break
}
return {
buildOptions,
}
}

View File

@ -1,5 +1,6 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import config from './cfg'
const pkg = require('./package.json')
const { dependencies, devDependencies, name, version } = pkg
@ -9,15 +10,10 @@ const __APP_INFO__ = {
}
import {
useAliasOptions,
useViteBuildPlugin,
useViteServerPlugin,
useEnvBuildOutput,
useAutoImport,
useViteComponents,
useViteCompression,
useVueI18nPlugin,
useHTMLTitlePlugin,
useSVGIcon,
} from './vite-plugin/index'
import vueJsx from '@vitejs/plugin-vue-jsx'
@ -26,23 +22,25 @@ import ViteInspect from 'vite-plugin-inspect'
import viteSvgLoader from 'vite-svg-loader'
import viteEslintPlugin from 'vite-plugin-eslint'
import vitePluginImp from 'vite-plugin-imp' // 按需打包工具
import { visualizer } from 'rollup-plugin-visualizer' // 打包体积分析工具
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
const { buildOptions } = useEnvBuildOutput(mode)
const { server, buildOptions, alias, title } = config
return {
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
resolve: {
alias: useAliasOptions(),
alias: alias,
},
plugins: [
vue({ reactivityTransform: true }),
vueJsx(),
title,
ViteInspect(), // 仅适用于开发模式(检查 `Vite` 插件的中间状态)
VueI18nPlugin(),
await useAutoImport([
@ -58,7 +56,6 @@ export default defineConfig(async ({ mode }) => {
await useViteComponents([NaiveUiResolver()]),
useViteCompression(),
useVueI18nPlugin(),
useHTMLTitlePlugin(),
viteSvgLoader({
defaultImport: 'component', // 默认以 `componetn` 形式导入 `svg`
}),
@ -76,6 +73,11 @@ export default defineConfig(async ({ mode }) => {
libDirectory: '',
camel2DashComponentName: false,
},
{
libName: '@vueuse',
libDirectory: '',
camel2DashComponentName: false,
},
],
}),
{
@ -88,12 +90,19 @@ export default defineConfig(async ({ mode }) => {
'src/*.vue',
],
},
visualizer({
gzipSize: true, // 搜集 `gzip` 压缩包
brotliSize: true, // 搜集 `brotli` 压缩包
emitFile: false, // 生成文件在根目录下
filename: 'visualizer.html',
open: true, // 以默认服务器代理打开文件
}),
],
optimizeDeps: {
include: ['vue', 'vue-router', 'pinia', 'vue-i18n', '@vueuse/core'],
},
build: {
...useViteBuildPlugin(buildOptions),
...buildOptions(mode),
},
css: {
preprocessorOptions: {
@ -104,7 +113,7 @@ export default defineConfig(async ({ mode }) => {
},
},
server: {
...useViteServerPlugin(),
...server,
},
}
})