Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plugin-mock-viewer to manage local mock data #6024

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/plugin-mock-viewer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 1.0.0

- The initial version of the plugin.
24 changes: 24 additions & 0 deletions packages/plugin-mock-viewer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# `plugin-mock-viewer`

plugin for manage local mock data in framework `ice`.

## Usage

```js
import mockViewer from '@ice/plugin-mock-viewer';

export default defineConfig({
plugins: [
mockViewer(
// port: 9006, // 可以自定义端口
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个传入的是对象?

// open: true, // 启动时打开mock数据管理页面
// debug: true, // 打印消息通信日志
)],
});
```

## Options

- port,可以自定义端口,默认9005
- open,启动时打开mock数据管理页面,默认false
- debug,打印消息通信日志,默认false
30 changes: 30 additions & 0 deletions packages/plugin-mock-viewer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@ice/plugin-mock-viewer",
"version": "1.0.0",
"description": "plugin for ice while manage local mock data",
"license": "MIT",
"type": "module",
"main": "./esm/index.js",
"types": "./esm/index.d.ts",
"files": [
"esm",
"!esm/**/*.map"
],
"devDependencies": {
"@ice/app": "^3.0.0"
},
"repository": {
"type": "http",
"url": "https://github.com/alibaba/ice/tree/master/packages/plugin-mock-viewer"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"watch": "tsc -w",
"build": "tsc"
},
"dependencies": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependencies 移动到 devDep 上面去

"webpack-mock-viewer": "^1.0.5"
}
}
22 changes: 22 additions & 0 deletions packages/plugin-mock-viewer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Plugin } from '@ice/app/types';
import type { WebpackMockViewerOptions } from 'webpack-mock-viewer';
import WebpackMockViewer from 'webpack-mock-viewer';


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多了一个空行

const mockViewer: Plugin<WebpackMockViewerOptions> = (options?: WebpackMockViewerOptions) => ({
// name 可选,插件名称
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释用英文, 这里没必要的可以删掉

name: 'plugin-mock-viewer',
// setup 必选,用于定制工程构建配置
setup: ({ context, onGetConfig }) => {
onGetConfig((webpackConfig) => {
if (context.command === 'start') {
if (!webpackConfig.plugins) webpackConfig.plugins = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以用 ??=

// 添加 webpack 插件
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种注释不要

webpackConfig.plugins.push(new WebpackMockViewer(options));
}
return webpackConfig;
});
},
});

export default mockViewer;
9 changes: 9 additions & 0 deletions packages/plugin-mock-viewer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "./",
"rootDir": "src",
"outDir": "esm"
},
"include": ["src"]
}
180 changes: 180 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.