Skip to content

Commit

Permalink
Merge branch 'template-dev' into template
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Jan 5, 2023
2 parents 4b0a3fc + ea23ee4 commit 64fed28
Show file tree
Hide file tree
Showing 40 changed files with 584 additions and 242 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
leadingUnderscore: 'allow',
filter: {
// you can expand this regex to add more allowed names
regex: '^((__v_.*)|[0-9]+)$',
regex: '^((__v_.*)|([0-9]+)|(__.*))$',
match: false,
},
},
Expand All @@ -74,6 +74,11 @@ module.exports = {
modifiers: ['const'],
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
filter: {
// you can expand this regex to add more allowed names
regex: '^__.*$',
match: false,
},
},
{
selector: ['memberLike'],
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dist-ssr
*.sln
*.sw?
package-lock.json
types/auto-imports.d.ts
types/meIconComments.d.ts
src/store/module.ts
types/directives.d.ts
Expand Down
3 changes: 3 additions & 0 deletions cli/autoImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ts-node
import autoImport from '../plugins/autoImport.js';
autoImport().buildStart();
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"scripts": {
"format": "prettier --write --cache .",
"dev": "vite",
"build": "vite build -m prod && npm run type-check",
"build-github": "vite build -m prod --base=/meadmin-template/ && npm run type-check",
"type-check": "vue-tsc --noEmit",
"build": "npm run type-check && vite build -m prod ",
"build-github": "npm run type-check && vite build -m prod --base=/meadmin-template/",
"type-check": "node --loader ts-node/esm ./cli/autoImport.ts && vue-tsc --noEmit",
"preview": "vite preview",
"release-main": "release-it -c .release-it-main.json",
"release-template": "release-it",
Expand Down Expand Up @@ -58,7 +58,7 @@
"@types/path-browserify": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"@vitejs/plugin-vue": "^3.0.0",
"@vitejs/plugin-vue": "^4.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"@yuntian001/vue-setup-extend": "^1.0.0",
"autoprefixer": "^10.4.8",
Expand All @@ -74,15 +74,16 @@
"rollup-plugin-visualizer": "^5.7.1",
"sass": "^1.53.0",
"terser": "^5.14.2",
"typescript": "^4.7.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"unplugin-auto-import": "^0.11.1",
"unplugin-vue-components": "^0.22.4",
"vite": "^3.0.0",
"vite": "^4.0.4",
"vite-plugin-autogeneration-import-file": "^3.0.0",
"vite-plugin-compression": "^0.5.1",
"vite-svg-loader": "^3.4.0",
"vue-eslint-parser": "^9.0.3",
"vue-tsc": "^1.0.9",
"vue-tsc": "^1.0.20",
"xregexp": "^5.1.1"
},
"repository": {
Expand Down
10 changes: 10 additions & 0 deletions plugins/autoComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { resolver } from './autoImport';
export default () =>
Components({
// 组件自动注册(包括components下的所有.vue组件和ElementPlus组件)
include: [],
dts: false,
resolvers: [ElementPlusResolver({ importStyle: false }), resolver([3], [2])],
});
64 changes: 64 additions & 0 deletions plugins/autoImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { dirname, resolve } from 'path';
import * as fs from 'fs';
import { createPlugin } from 'vite-plugin-autogeneration-import-file';
import { fileURLToPath } from 'url';
const { autoImport, resolver: resolverFn } = createPlugin();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(filename);
function pathResolve(dir: string) {
return resolve(__dirname, '../', dir);
}
export default () =>
autoImport([
// 自动生成
{
// svg icon type
pattern: ['*.svg'],
dir: pathResolve('src/icons/svg'),
toFile: pathResolve('types/meIconComments.d.ts'),
name: 'MeIcon_{{name}}',
template: fs.readFileSync(pathResolve('./template/meIconComments.d.ts'), 'utf-8'),
codeTemplates: [{ key: '//code', template: '{{name}}: Icon;\n ' }],
},
{
// pinia module
pattern: ['**/*.{ts,js}', '*.{ts,js}'],
dir: pathResolve('src/store/modules'),
toFile: pathResolve('src/store/module.ts'),
name: 'use_{{name}}_store',
},
{
// auto import directives
pattern: ['*.ts', '**/index.ts'],
dir: pathResolve('src/directives'),
toFile: pathResolve('types/directives.d.ts'),
template: fs.readFileSync(pathResolve('./template/directives.d.ts'), 'utf-8'),
codeTemplates: [
{
key: '//code',
template: '{{name}}: typeof import("{{path}}")["default"];\n ',
},
],
name: 'V_{{name}}',
},
{
// auto import components
pattern: ['*.{vue,ts}', '**/index.{vue,ts}'],
dir: pathResolve('src/components'),
toFile: pathResolve('types/components.d.ts'),
template: fs.readFileSync(pathResolve('./template/components.d.ts'), 'utf-8'),
codeTemplates: [
{
key: '//code',
template: '{{name}}: typeof import("{{path}}")["default"];\n ',
},
{
key: '//typeCode',
template: 'type {{name}}Instance = InstanceType<typeof import("{{path}}")["default"]>;\n ',
},
],
name: '_{{name}}',
},
]);

export const resolver = resolverFn;
14 changes: 14 additions & 0 deletions plugins/autoImportApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AutoImport from 'unplugin-auto-import/vite';
import { resolve } from 'path';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
function pathResolve(dir: string) {
return resolve(__dirname, '../', dir);
}
export default () =>
AutoImport({
// 自动加载API
imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
// 可以选择auto-imports.d.ts生成的位置,使用ts建议设置为'src/auto-imports.d.ts'
dts: pathResolve('types/auto-imports.d.ts'),
resolvers: [ElementPlusResolver()],
});
25 changes: 25 additions & 0 deletions plugins/babel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { babel } from '@rollup/plugin-babel';
import { createRequire } from 'node:module';
export default () =>
babel({
babelrc: false,
extensions: ['.ts', '.tsx'],
plugins: [['@babel/plugin-transform-runtime', { useESModules: true }]],
presets: [
[
'@babel/preset-env',
{
targets: ['chrome 87', 'safari 13', 'firefox 78', 'edge 88'],
useBuiltIns: 'usage',
bugfixes: true,
loose: false,
modules: false,
corejs: createRequire(import.meta.url)('core-js/package.json').version,
shippedProposals: true,
ignoreBrowserslistConfig: true,
},
],
],
exclude: 'node_modules/**',
babelHelpers: 'runtime',
});
34 changes: 34 additions & 0 deletions plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ConfigEnv } from 'vite';
import autoComponents from './autoComponents';
import autoImport from './autoImport';
import autoImportApi from './autoImportApi';
import babel from './babel';
import mock from './mock';
import svgLoader from './svgLoader';
import vueSetUpExtend from './vueSetUpExtend';
import { visualizer } from 'rollup-plugin-visualizer'; //打包大小分析(stats.html)
import vue from '@vitejs/plugin-vue';
// import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import { splitVendorChunkPlugin } from 'vite';
import viteCompression from 'vite-plugin-compression'; //打包压缩

export default (configEnv: ConfigEnv) => {
return [
vue(),
splitVendorChunkPlugin(), //打包分析,会生成stats.html展示打包情况
// VueI18nPlugin({
// /* options */
// // locale messages resource pre-compile option
// include: ['./src/**/lang/**/*.json', './src/**/lang/*.json'],
// }),
visualizer(),
viteCompression(),
autoComponents(),
autoImport(),
autoImportApi(),
babel(),
mock(configEnv),
svgLoader(),
vueSetUpExtend(),
];
};
13 changes: 13 additions & 0 deletions plugins/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { viteMockServe } from '@meadmin-cn/vite-plugin-mock';
import { ConfigEnv } from 'vite';
export default ({ command }: ConfigEnv) =>
viteMockServe({
mockPath: 'mock/apiDemo',
localEnabled: command === 'serve',
prodEnabled: command !== 'serve',
// 这样可以控制关闭mock的时候不让mock打包到最终代码内
injectCode: `
import { setupProdMockServer } from '../mock/index';
setupProdMockServer();
`,
});
22 changes: 22 additions & 0 deletions plugins/svgLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import svgLoader from 'vite-svg-loader';
export default () =>
svgLoader({
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false, // 禁用插件
},
},
},
{
name: 'removeAttrs',
params: {
attrs: '(width|height|fill)', // 清除svg属性
},
},
],
},
});
9 changes: 9 additions & 0 deletions plugins/vueSetUpExtend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { vueSetUpExtend } from '@yuntian001/vue-setup-extend';
// @ts-ignore
import { loadMessageConfig } from '../src/config/locale';
export default () =>
vueSetUpExtend({
exclude: ['steup', 'lang'],
setLangImport: loadMessageConfig.componentLoad,
setComponents: loadMessageConfig.componentLoad,
});
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</template>
<script setup lang="ts">
import { useSettingStore } from '@/store';
import { SizeEnum } from '@/enums/configEnum';
import { SizeEnum } from '@/dict/configEnum';
const settingStore = useSettingStore();
const htmlDom = document.getElementsByTagName('html')[0];
watchEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/meKeepAlive/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
queuePostFlushCb,
} from 'vue';
import { queueEffectWithSuspense } from './Suspense';
import {getGlobalThis} from '@vue/shared';
const globalThis = getGlobalThis();


// An object exposing the internals of a renderer, passed to tree-shakeable
// features so that they can be decoupled from this file. Keys are shortened
Expand Down Expand Up @@ -111,7 +114,7 @@ type PatchBlockChildrenFn = (

type NextFn = (vnode: VNode) => RendererNode | null;

export const queuePostRenderEffect = __FEATURE_SUSPENSE__ ? queueEffectWithSuspense : queuePostFlushCb;
export const queuePostRenderEffect = globalThis.__FEATURE_SUSPENSE__ ? queueEffectWithSuspense : queuePostFlushCb;

export type SetupRenderEffectFn = (
instance: ComponentInternalInstance,
Expand Down
16 changes: 8 additions & 8 deletions src/components/meKeepAlive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import {
import { getComponentName } from './core/component';
import { invokeVNodeHook } from './core/vnode';
import { warn } from './core/warning';
import { isString, isArray, invokeArrayFns } from '@vue/shared';
import { isString, isArray, invokeArrayFns,getGlobalThis } from '@vue/shared';
import { ShapeFlags } from './core/shapeFlags';
import { RendererInternals, queuePostRenderEffect, MoveType } from './core/renderer';
import { ComponentRenderContext } from './core/componentPublicInstance';
import { devtoolsComponentAdded } from './core/devtools';
import { isAsyncWrapper } from './core/apiAsyncComponent';
import { isSuspense } from './core/Suspense';
type MatchPattern = string | RegExp | Array<string | RegExp>;

const globalThis = getGlobalThis();
export interface MeKeepAliveProps {
include?: MatchPattern;
exclude?: MatchPattern;
Expand Down Expand Up @@ -77,7 +77,7 @@ const KeepAliveImpl: ComponentOptions = {

// if the internal renderer is not registered, it indicates that this is server-side rendering,
// for KeepAlive, we just need to render its children
if (__SSR__ && !sharedContext.renderer) {
if (globalThis.__SSR__ && !sharedContext.renderer) {
return () => {
const children = slots.default && slots.default();
return children && children.length === 1 ? children[0] : children;
Expand All @@ -88,7 +88,7 @@ const KeepAliveImpl: ComponentOptions = {
const keys: Keys = new Set();
let current: VNode | null = null;

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
if (globalThis.__DEV__ || globalThis.__FEATURE_PROD_DEVTOOLS__) {
(instance as any).__v_cache = cache;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ const KeepAliveImpl: ComponentOptions = {
}
}, parentSuspense);

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
if (globalThis.__DEV__ || globalThis.__FEATURE_PROD_DEVTOOLS__) {
// Update components tree
devtoolsComponentAdded(instance);
}
Expand All @@ -140,7 +140,7 @@ const KeepAliveImpl: ComponentOptions = {
instance.isDeactivated = true;
}, parentSuspense);

if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
if (globalThis.__DEV__ || globalThis.__FEATURE_PROD_DEVTOOLS__) {
// Update components tree
devtoolsComponentAdded(instance);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ const KeepAliveImpl: ComponentOptions = {
const children = slots.default();
const rawVNode = children[0];
if (children.length > 1) {
if (__DEV__) {
if (globalThis.__DEV__) {
warn(`KeepAlive should contain exactly one component child.`, current);
}
current = null;
Expand Down Expand Up @@ -318,7 +318,7 @@ const KeepAliveImpl: ComponentOptions = {
},
};

if (__COMPAT__) {
if (globalThis.__COMPAT__) {
KeepAliveImpl.__isBuildIn = true;
}

Expand Down
Loading

0 comments on commit 64fed28

Please sign in to comment.