Skip to content

Commit

Permalink
feat: 添加 console 配置,支持输出 version
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Nov 28, 2024
1 parent 2cc5915 commit 0a9a12a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
16 changes: 16 additions & 0 deletions docs/reference/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ export default {
};
```

### console

- 类型: `object`
- 默认值:`{}`
- 详情:
用于控制应用启动的时候在 console 中打印的信息,目前仅支持 version
- 示例:

```js
export default {
console: {
version: true
}
};
```

### define

- 类型: `object`
Expand Down
1 change: 1 addition & 0 deletions packages/fes-preset-built-in/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions packages/fes-preset-built-in/src/plugins/core/entry/fes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import DefaultContainer from './defaultContainer.vue';

{{{ entryCodeAhead }}}

{{{ CONSOLE }}}

const renderClient = (opts = {}) => {
const { plugin, routes, rootElement } = opts;
const rootContainer = plugin.applyPlugins({
Expand Down
10 changes: 10 additions & 0 deletions packages/fes-preset-built-in/src/plugins/core/entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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'}`,
Expand Down
13 changes: 13 additions & 0 deletions packages/fes-preset-built-in/src/plugins/features/console.js
Original file line number Diff line number Diff line change
@@ -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');
},
},
});
};
17 changes: 10 additions & 7 deletions packages/fes-preset-built-in/types.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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[];
Expand Down
3 changes: 3 additions & 0 deletions packages/fes-template/.fes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default defineBuildConfig({
define: {
__DEV__: false,
},
console: {
version: true,
},
html: {
title: '海贼王',
},
Expand Down

0 comments on commit 0a9a12a

Please sign in to comment.