From c3e294ff76aff4654c7218645c7a13b539f66a36 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期二, 18 六月 2024 20:08:43 +0800 Subject: [PATCH] internal --- internal/vite-config/src/plugins/appConfig.ts | 14 ++ internal/eslint-config/src/index.ts | 17 +-- internal/stylelint-config/src/index.ts | 3 internal/vite-config/package.json | 36 ++++---- internal/vite-config/src/utils/env.ts | 7 + internal/vite-config/src/config/application.ts | 20 ++--- internal/eslint-config/package.json | 19 ++-- internal/ts-config/vue-app.json | 1 internal/vite-config/src/utils/modifyVars.ts | 16 ++- internal/stylelint-config/package.json | 26 +++--- internal/ts-config/package.json | 8 +- internal/vite-config/src/utils/hash.ts | 10 ++ internal/vite-config/src/config/common.ts | 13 +-- internal/vite-config/src/config/package.ts | 4 internal/vite-config/src/plugins/index.ts | 22 +++-- internal/ts-config/base.json | 2 16 files changed, 117 insertions(+), 101 deletions(-) diff --git a/internal/eslint-config/package.json b/internal/eslint-config/package.json index 8341b1f..2e075f8 100644 --- a/internal/eslint-config/package.json +++ b/internal/eslint-config/package.json @@ -12,6 +12,7 @@ "directory": "internal/eslint-config" }, "license": "MIT", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", @@ -36,14 +37,14 @@ "stub": "pnpm unbuild --stub" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^5.57.1", - "@typescript-eslint/parser": "^5.57.1", - "eslint": "^8.37.0", - "eslint-config-prettier": "^8.8.0", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-prettier": "^4.2.1", - "eslint-plugin-simple-import-sort": "^10.0.0", - "eslint-plugin-vue": "^9.10.0", - "vue-eslint-parser": "^9.1.1" + "@typescript-eslint/eslint-plugin": "^7.0.1", + "@typescript-eslint/parser": "^7.0.1", + "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-simple-import-sort": "^12.0.0", + "eslint-plugin-vue": "^9.21.1", + "vue-eslint-parser": "^9.4.2" } } diff --git a/internal/eslint-config/src/index.ts b/internal/eslint-config/src/index.ts index 101e338..1138bb3 100644 --- a/internal/eslint-config/src/index.ts +++ b/internal/eslint-config/src/index.ts @@ -25,7 +25,6 @@ 'plugin:prettier/recommended', ], rules: { - 'no-undef': 'off', 'no-unused-vars': 'off', 'no-case-declarations': 'off', 'no-use-before-define': 'off', @@ -35,14 +34,13 @@ 'import/newline-after-import': 'error', 'import/no-duplicates': 'error', - // '@typescript-eslint/no-unused-vars': [ - // 'error', - // { - // argsIgnorePattern: '^_', - // varsIgnorePattern: '^_', - // }, - // ], - '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_', + }, + ], '@typescript-eslint/ban-ts-ignore': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/ban-types': 'off', @@ -65,7 +63,6 @@ 'vue/attribute-hyphenation': 'off', 'vue/require-default-prop': 'off', 'vue/require-explicit-emits': 'off', - 'vue/v-on-event-hyphenation': 'off', 'vue/html-self-closing': [ 'error', { diff --git a/internal/stylelint-config/package.json b/internal/stylelint-config/package.json index ccd90ee..18dd5d2 100644 --- a/internal/stylelint-config/package.json +++ b/internal/stylelint-config/package.json @@ -12,6 +12,7 @@ "directory": "internal/stylelint-config" }, "license": "MIT", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", @@ -31,19 +32,18 @@ "stub": "pnpm unbuild --stub" }, "devDependencies": { - "postcss": "^8.4.21", - "postcss-html": "^1.5.0", + "postcss": "^8.4.38", + "postcss-html": "^1.6.0", "postcss-less": "^6.0.0", - "postcss-scss": "^4.0.6", - "prettier": "^2.8.7", - "stylelint": "^15.4.0", - "stylelint-config-property-sort-order-smacss": "^9.1.0", - "stylelint-config-recommended": "^11.0.0", - "stylelint-config-recommended-scss": "^9.0.1", - "stylelint-config-recommended-vue": "^1.4.0", - "stylelint-config-standard": "^32.0.0", - "stylelint-config-standard-scss": "^7.0.1", - "stylelint-order": "^6.0.3", - "stylelint-prettier": "^3.0.0" + "postcss-scss": "^4.0.9", + "prettier": "^3.2.5", + "stylelint": "^16.4.0", + "stylelint-config-property-sort-order-smacss": "^10.0.0", + "stylelint-config-recommended-scss": "^14.0.0", + "stylelint-config-recommended-vue": "^1.5.0", + "stylelint-config-standard": "^36.0.0", + "stylelint-config-standard-scss": "^13.1.0", + "stylelint-order": "^6.0.4", + "stylelint-prettier": "^5.0.0" } } diff --git a/internal/stylelint-config/src/index.ts b/internal/stylelint-config/src/index.ts index 3dc0475..8b15456 100644 --- a/internal/stylelint-config/src/index.ts +++ b/internal/stylelint-config/src/index.ts @@ -22,6 +22,8 @@ }, ], rules: { + 'prettier/prettier': true, + 'media-feature-range-notation': null, 'selector-not-notation': null, 'import-notation': null, 'function-no-unknown': null, @@ -57,7 +59,6 @@ }, ], 'no-empty-source': null, - 'string-quotes': null, 'named-grid-areas-no-invalid': null, 'no-descending-specificity': null, 'font-family-no-missing-generic-family-keyword': null, diff --git a/internal/ts-config/base.json b/internal/ts-config/base.json index ab99195..8b90054 100644 --- a/internal/ts-config/base.json +++ b/internal/ts-config/base.json @@ -4,7 +4,7 @@ "compilerOptions": { "target": "ESNext", "module": "ESNext", - "moduleResolution": "node", + "moduleResolution": "bundler", "strict": true, "declaration": true, "noImplicitOverride": true, diff --git a/internal/ts-config/package.json b/internal/ts-config/package.json index 9c0e783..dd968c8 100644 --- a/internal/ts-config/package.json +++ b/internal/ts-config/package.json @@ -12,15 +12,15 @@ "directory": "internal/ts-config" }, "license": "MIT", + "type": "module", "files": [ "base.json", "node.json", - "vue.json", + "vue-app.json", "node-server.json" ], "dependencies": { - "@types/node": "^18.15.11", - "unplugin-vue-define-options": "^1.3.3", - "vite": "^4.3.0-beta.2" + "@types/node": "^20.12.7", + "vite": "^5.2.10" } } diff --git a/internal/ts-config/vue-app.json b/internal/ts-config/vue-app.json index ac9636b..02f3fd2 100644 --- a/internal/ts-config/vue-app.json +++ b/internal/ts-config/vue-app.json @@ -6,6 +6,5 @@ "jsx": "preserve", "lib": ["ESNext", "DOM"], "noImplicitAny": false - } } diff --git a/internal/vite-config/package.json b/internal/vite-config/package.json index d9f3de2..86d44e2 100644 --- a/internal/vite-config/package.json +++ b/internal/vite-config/package.json @@ -12,6 +12,7 @@ "directory": "internal/vite-config" }, "license": "MIT", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", @@ -31,29 +32,28 @@ "stub": "pnpm unbuild --stub" }, "dependencies": { - "@ant-design/colors": "^7.0.0", - "vite": "^4.3.0-beta.2" + "@ant-design/colors": "^7.0.2", + "vite": "^5.2.10" }, "devDependencies": { - "@types/fs-extra": "^11.0.1", - "@vitejs/plugin-vue": "^4.1.0", - "@vitejs/plugin-vue-jsx": "^3.0.1", - "ant-design-vue": "^3.2.17", - "dayjs": "^1.11.7", - "dotenv": "^16.0.3", - "fs-extra": "^11.1.1", - "less": "^4.1.3", + "@types/fs-extra": "^11.0.4", + "@vitejs/plugin-vue": "^5.0.4", + "@vitejs/plugin-vue-jsx": "^3.1.0", + "ant-design-vue": "^4.2.1", + "dayjs": "^1.11.10", + "dotenv": "^16.4.5", + "fs-extra": "^11.2.0", + "less": "^4.2.0", "picocolors": "^1.0.0", - "pkg-types": "^1.0.2", - "rollup-plugin-visualizer": "^5.9.0", - "sass": "^1.60.0", - "unocss": "^0.50.6", - "unplugin-vue-define-options": "^1.3.3", + "pkg-types": "^1.1.0", + "rollup-plugin-visualizer": "^5.12.0", + "sass": "^1.75.0", + "unocss": "0.59.4", "vite-plugin-compression": "^0.5.1", - "vite-plugin-dts": "^2.2.0", - "vite-plugin-html": "^3.2.0", + "vite-plugin-dts": "^3.9.0", + "vite-plugin-html": "^3.2.2", "vite-plugin-mock": "^2.9.6", - "vite-plugin-purge-icons": "^0.9.2", + "vite-plugin-purge-icons": "^0.10.0", "vite-plugin-svg-icons": "^2.0.1" } } diff --git a/internal/vite-config/src/config/application.ts b/internal/vite-config/src/config/application.ts index 92c6934..7ee5ef1 100644 --- a/internal/vite-config/src/config/application.ts +++ b/internal/vite-config/src/config/application.ts @@ -21,7 +21,10 @@ return defineConfig(async ({ command, mode }) => { const root = process.cwd(); const isBuild = command === 'build'; - const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_ENABLE_ANALYZE } = loadEnv(mode, root); + const { VITE_PUBLIC_PATH, VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_ENABLE_ANALYZE } = loadEnv( + mode, + root, + ); const defineData = await createDefineData(root); const plugins = await createPlugins({ @@ -35,21 +38,12 @@ const pathResolve = (pathname: string) => resolve(root, '.', pathname); const applicationConfig: UserConfig = { + base: VITE_PUBLIC_PATH, resolve: { alias: [ { find: 'vue-i18n', replacement: 'vue-i18n/dist/vue-i18n.cjs.js', - }, - // /@/xxxx => src/xxxx - { - find: /\/@\//, - replacement: pathResolve('src') + '/', - }, - // /#/xxxx => types/xxxx - { - find: /\/#\//, - replacement: pathResolve('types') + '/', }, // @/xxxx => src/xxxx { @@ -69,6 +63,8 @@ cssTarget: 'chrome80', rollupOptions: { output: { + // 鍏ュ彛鏂囦欢鍚� + entryFileNames: 'assets/entry/[name]-[hash].js', manualChunks: { vue: ['vue', 'pinia', 'vue-router'], antd: ['ant-design-vue', '@ant-design/icons-vue'], @@ -87,7 +83,7 @@ plugins, }; - const mergedConfig = mergeConfig(commonConfig, applicationConfig); + const mergedConfig = mergeConfig(commonConfig(mode), applicationConfig); return mergeConfig(mergedConfig, overrides); }); diff --git a/internal/vite-config/src/config/common.ts b/internal/vite-config/src/config/common.ts index 8a56c89..559896e 100644 --- a/internal/vite-config/src/config/common.ts +++ b/internal/vite-config/src/config/common.ts @@ -1,13 +1,12 @@ -import { presetTypography, presetUno } from 'unocss'; import UnoCSS from 'unocss/vite'; import { type UserConfig } from 'vite'; -const commonConfig: UserConfig = { +const commonConfig: (mode: string) => UserConfig = (mode) => ({ server: { host: true, }, esbuild: { - drop: ['console', 'debugger'], + drop: mode === 'production' ? ['console', 'debugger'] : [], }, build: { reportCompressedSize: false, @@ -17,11 +16,7 @@ maxParallelFileOps: 3, }, }, - plugins: [ - UnoCSS({ - presets: [presetUno(), presetTypography()], - }), - ], -}; + plugins: [UnoCSS()], +}); export { commonConfig }; diff --git a/internal/vite-config/src/config/package.ts b/internal/vite-config/src/config/package.ts index cb6dd19..ab83852 100644 --- a/internal/vite-config/src/config/package.ts +++ b/internal/vite-config/src/config/package.ts @@ -14,7 +14,7 @@ function definePackageConfig(defineOptions: DefineOptions = {}) { const { overrides = {} } = defineOptions; const root = process.cwd(); - return defineConfig(async () => { + return defineConfig(async ({ mode }) => { const { dependencies = {}, peerDependencies = {} } = await readPackageJSON(root); const packageConfig: UserConfig = { build: { @@ -33,7 +33,7 @@ }), ], }; - const mergedConfig = mergeConfig(commonConfig, packageConfig); + const mergedConfig = mergeConfig(commonConfig(mode), packageConfig); return mergeConfig(mergedConfig, overrides); }); diff --git a/internal/vite-config/src/plugins/appConfig.ts b/internal/vite-config/src/plugins/appConfig.ts index a4fb954..7d50662 100644 --- a/internal/vite-config/src/plugins/appConfig.ts +++ b/internal/vite-config/src/plugins/appConfig.ts @@ -27,8 +27,8 @@ return { name: PLUGIN_NAME, async configResolved(_config) { - let appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? ''; - appTitle = appTitle.replace(/\s/g, '_').replace(/-/g, '_'); + const appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? ''; + // appTitle = appTitle.replace(/\s/g, '_').replace(/-/g, '_'); publicPath = _config.base; source = await getConfigSource(appTitle); }, @@ -74,7 +74,15 @@ * @param env */ const getVariableName = (title: string) => { - return `__PRODUCTION__${title || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); + function strToHex(str: string) { + const result: string[] = []; + for (let i = 0; i < str.length; ++i) { + const hex = str.charCodeAt(i).toString(16); + result.push(('000' + hex).slice(-4)); + } + return result.join('').toUpperCase(); + } + return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); }; async function getConfigSource(appTitle: string) { diff --git a/internal/vite-config/src/plugins/index.ts b/internal/vite-config/src/plugins/index.ts index 79aae58..9ce7a66 100644 --- a/internal/vite-config/src/plugins/index.ts +++ b/internal/vite-config/src/plugins/index.ts @@ -1,9 +1,16 @@ +/* + * @Description: file content + * @Author: Ben Lin + * @version: + * @Date: 2024-06-17 14:51:25 + * @LastEditors: Ben Lin + * @LastEditTime: 2024-06-18 10:38:24 + */ import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; -// @ts-ignore: type unless -import DefineOptions from 'unplugin-vue-define-options/vite'; import { type PluginOption } from 'vite'; import purgeIcons from 'vite-plugin-purge-icons'; +import DevTools from 'vite-plugin-vue-devtools'; import { createAppConfigPlugin } from './appConfig'; import { configCompressPlugin } from './compress'; @@ -11,7 +18,7 @@ import { configMockPlugin } from './mock'; import { configSvgIconsPlugin } from './svgSprite'; import { configVisualizerConfig } from './visualizer'; -import vueSetupExtend from 'vite-plugin-vue-setup-extend'; + interface Options { isBuild: boolean; root: string; @@ -21,16 +28,13 @@ } async function createPlugins({ isBuild, root, enableMock, compress, enableAnalyze }: Options) { - const vitePlugins: (PluginOption | PluginOption[])[] = [ - vue(), - vueJsx(), - vueSetupExtend(), - DefineOptions(), - ]; + const vitePlugins: (PluginOption | PluginOption[])[] = [vue(), vueJsx()]; const appConfigPlugin = await createAppConfigPlugin({ root, isBuild }); vitePlugins.push(appConfigPlugin); + // vitePlugins.push(DevTools()); + // vite-plugin-html vitePlugins.push(configHtmlPlugin({ isBuild })); diff --git a/internal/vite-config/src/utils/env.ts b/internal/vite-config/src/utils/env.ts index 648d873..c84ea94 100644 --- a/internal/vite-config/src/utils/env.ts +++ b/internal/vite-config/src/utils/env.ts @@ -22,7 +22,12 @@ * @param match prefix * @param confFiles ext */ -export async function getEnvConfig(match = 'VITE_GLOB_', confFiles = getConfFiles()) { +export async function getEnvConfig( + match = 'VITE_GLOB_', + confFiles = getConfFiles(), +): Promise<{ + [key: string]: string; +}> { let envConfig = {}; for (const confFile of confFiles) { diff --git a/internal/vite-config/src/utils/hash.ts b/internal/vite-config/src/utils/hash.ts index 83dc0fd..0b5a7c9 100644 --- a/internal/vite-config/src/utils/hash.ts +++ b/internal/vite-config/src/utils/hash.ts @@ -4,5 +4,13 @@ const hash = createHash('sha256').update(content); return hash.digest('hex').slice(0, hashLSize); } +function strToHex(str: string) { + const result: string[] = []; + for (let i = 0; i < str.length; ++i) { + const hex = str.charCodeAt(i).toString(16); + result.push(('000' + hex).slice(-4)); + } + return result.join('').toUpperCase(); +} -export { createContentHash }; +export { createContentHash, strToHex }; diff --git a/internal/vite-config/src/utils/modifyVars.ts b/internal/vite-config/src/utils/modifyVars.ts index 8ac8a8f..0554343 100644 --- a/internal/vite-config/src/utils/modifyVars.ts +++ b/internal/vite-config/src/utils/modifyVars.ts @@ -2,8 +2,11 @@ import { generate } from '@ant-design/colors'; // @ts-ignore: typo -import { getThemeVariables } from 'ant-design-vue/dist/theme'; +/* import { getThemeVariables } from 'ant-design-vue/dist/theme'; */ +import { theme } from 'ant-design-vue/lib'; +import convertLegacyToken from 'ant-design-vue/lib/theme/convertLegacyToken'; +const { defaultAlgorithm, defaultSeed } = theme; const primaryColor = '#0960bd'; function generateAntColors(color: string, theme: 'default' | 'dark' = 'default') { @@ -18,18 +21,18 @@ export function generateModifyVars() { const palettes = generateAntColors(primaryColor); const primary = palettes[5]; - const primaryColorObj: Record<string, string> = {}; for (let index = 0; index < 10; index++) { primaryColorObj[`primary-${index + 1}`] = palettes[index]; } - - const modifyVars = getThemeVariables(); + // const modifyVars = getThemeVariables(); + const mapToken = defaultAlgorithm(defaultSeed); + const v3Token = convertLegacyToken(mapToken); return { - ...modifyVars, + ...v3Token, // reference: Avoid repeated references - hack: `${modifyVars.hack} @import (reference) "${resolve('src/design/config.less')}";`, + hack: `true; @import (reference) "${resolve('src/design/config.less')}";`, 'primary-color': primary, ...primaryColorObj, 'info-color': primary, @@ -40,6 +43,5 @@ 'font-size-base': '14px', // Main font size 'border-radius-base': '2px', // Component/float fillet 'link-color': primary, // Link color - 'app-content-background': '#fafafa', // Link color }; } -- Gitblit v1.9.3