From 4c9941503eb2d28089321e61ecf0e4c29463e3f9 Mon Sep 17 00:00:00 2001 From: qlin Date: Fri, 29 Nov 2024 10:58:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20console=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE,=E6=94=AF=E6=8C=81=E8=BE=93=E5=87=BA=20versi?= =?UTF-8?q?on=20(#263)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/reference/config/index.md | 16 ++++++++++++++++ packages/fes-preset-built-in/src/index.js | 1 + .../src/plugins/core/entry/fes.tpl | 2 ++ .../src/plugins/core/entry/index.js | 10 ++++++++++ .../src/plugins/features/console.js | 13 +++++++++++++ packages/fes-preset-built-in/types.d.ts | 17 ++++++++++------- packages/fes-template/.fes.js | 3 +++ 7 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 packages/fes-preset-built-in/src/plugins/features/console.js diff --git a/docs/reference/config/index.md b/docs/reference/config/index.md index 0c0129429..3c892f26a 100644 --- a/docs/reference/config/index.md +++ b/docs/reference/config/index.md @@ -93,6 +93,22 @@ export default { }; ``` +### console + +- 类型: `object` +- 默认值:`{}` +- 详情: + 用于控制应用启动的时候在 console 中打印的信息,目前仅支持 version +- 示例: + +```js +export default { + console: { + version: true + } +}; +``` + ### define - 类型: `object` diff --git a/packages/fes-preset-built-in/src/index.js b/packages/fes-preset-built-in/src/index.js index add31ded0..dd45e28b9 100644 --- a/packages/fes-preset-built-in/src/index.js +++ b/packages/fes-preset-built-in/src/index.js @@ -16,6 +16,7 @@ export default function () { require.resolve('./plugins/features/alias'), require.resolve('./plugins/features/autoprefixer'), require.resolve('./plugins/features/define'), + require.resolve('./plugins/features/console'), require.resolve('./plugins/features/dynamicImport'), require.resolve('./plugins/features/globalCSS'), require.resolve('./plugins/features/inlineLimit'), diff --git a/packages/fes-preset-built-in/src/plugins/core/entry/fes.tpl b/packages/fes-preset-built-in/src/plugins/core/entry/fes.tpl index fe78c2603..df1a9157c 100644 --- a/packages/fes-preset-built-in/src/plugins/core/entry/fes.tpl +++ b/packages/fes-preset-built-in/src/plugins/core/entry/fes.tpl @@ -12,6 +12,8 @@ import DefaultContainer from './defaultContainer.vue'; {{{ entryCodeAhead }}} +{{{ CONSOLE }}} + const renderClient = (opts = {}) => { const { plugin, routes, rootElement } = opts; const rootContainer = plugin.applyPlugins({ diff --git a/packages/fes-preset-built-in/src/plugins/core/entry/index.js b/packages/fes-preset-built-in/src/plugins/core/entry/index.js index 345221b80..50f91301b 100644 --- a/packages/fes-preset-built-in/src/plugins/core/entry/index.js +++ b/packages/fes-preset-built-in/src/plugins/core/entry/index.js @@ -13,6 +13,15 @@ export function importsToStr(imports) { }); } +function getConsoleInfo(config, pkg) { + if (config.console?.version) { + return ` +console.log('%c[${pkg.name}]%c${pkg.version}', 'background-color: #1677ff; border-top-left-radius: 6px; border-bottom-left-radius: 6px; color: white; padding: 4px', 'background-color: #42b983; border-top-right-radius: 6px; border-bottom-right-radius: 6px; color: white; padding: 4px'); + `; + } + return ''; +} + export default function (api) { const { utils: { Mustache }, @@ -24,6 +33,7 @@ export default function (api) { path: 'fes.js', content: Mustache.render(fesTpl, { enableTitle: api.config.title !== false, + CONSOLE: getConsoleInfo(api.config, api.pkg), defaultTitle: api.config.title || 'fes.js', runtimePath, rootElement: `#${api.config.mountElementId || 'app'}`, diff --git a/packages/fes-preset-built-in/src/plugins/features/console.js b/packages/fes-preset-built-in/src/plugins/features/console.js new file mode 100644 index 000000000..06d57dab4 --- /dev/null +++ b/packages/fes-preset-built-in/src/plugins/features/console.js @@ -0,0 +1,13 @@ +export default (api) => { + api.describe({ + key: 'console', + config: { + default: { + version: false, + }, + schema(joi) { + return joi.object().description('output info in console, default version'); + }, + }, + }); +}; diff --git a/packages/fes-preset-built-in/types.d.ts b/packages/fes-preset-built-in/types.d.ts index 20e397428..652f6d5e5 100644 --- a/packages/fes-preset-built-in/types.d.ts +++ b/packages/fes-preset-built-in/types.d.ts @@ -1,8 +1,8 @@ -import { Component, DefineComponent, Component, App } from 'vue'; -import { RouteRecordRaw, Router, RouterHistory, createMemoryHistory, createWebHashHistory, createWebHistory } from 'vue-router'; +import type { App, Component, DefineComponent } from 'vue'; +import type { createMemoryHistory, createWebHashHistory, createWebHistory, Router, RouteRecordRaw, RouterHistory } from 'vue-router'; // @ts-ignore -import { Plugin } from '@fesjs/runtime'; +import type { Plugin } from '@fesjs/runtime'; interface BeforeRenderConfig { loading: Component; @@ -44,6 +44,9 @@ declare module '@fesjs/fes' { interface PluginBuildConfig { globalCSS?: 'beforeImports' | 'afterImports'; alias?: Record; + console?: { + version?: boolean; + }; autoprefixer?: { /** environment for `Browserslist` */ env?: string; @@ -86,10 +89,10 @@ declare module '@fesjs/fes' { dynamicImport?: boolean; inlineLimit?: number; mock?: - | boolean - | { - prefix?: string; - }; + | boolean + | { + prefix?: string; + }; mountElementId?: string; plugins?: string[]; presets?: string[]; diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index 43ef8db8e..9efda3fc3 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -8,6 +8,9 @@ export default defineBuildConfig({ define: { __DEV__: false, }, + console: { + version: true, + }, html: { title: '海贼王', },