feat: 添加 console 配置,支持输出 version

This commit is contained in:
winixt 2024-11-28 16:31:09 +08:00
parent 2cc5915ea7
commit 0a9a12a314
7 changed files with 55 additions and 7 deletions

View File

@ -93,6 +93,22 @@ export default {
};
```
### console
- 类型: `object`
- 默认值:`{}`
- 详情:
用于控制应用启动的时候在 console 中打印的信息,目前仅支持 version
- 示例:
```js
export default {
console: {
version: true
}
};
```
### define
- 类型: `object`

View File

@ -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'),

View File

@ -12,6 +12,8 @@ import DefaultContainer from './defaultContainer.vue';
{{{ entryCodeAhead }}}
{{{ CONSOLE }}}
const renderClient = (opts = {}) => {
const { plugin, routes, rootElement } = opts;
const rootContainer = plugin.applyPlugins({

View File

@ -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'}`,

View File

@ -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');
},
},
});
};

View File

@ -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<string, string>;
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[];

View File

@ -8,6 +8,9 @@ export default defineBuildConfig({
define: {
__DEV__: false,
},
console: {
version: true,
},
html: {
title: '海贼王',
},