-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## 1.0.0 | ||
|
||
- The initial version of the plugin. |
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, // 可以自定义端口 | ||
// open: true, // 启动时打开mock数据管理页面 | ||
// debug: true, // 打印消息通信日志 | ||
)], | ||
}); | ||
``` | ||
|
||
## Options | ||
|
||
- port,可以自定义端口,默认9005 | ||
- open,启动时打开mock数据管理页面,默认false | ||
- debug,打印消息通信日志,默认false |
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": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dependencies 移动到 devDep 上面去 |
||
"webpack-mock-viewer": "^1.0.5" | ||
} | ||
} |
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'; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 多了一个空行 |
||
const mockViewer: Plugin<WebpackMockViewerOptions> = (options?: WebpackMockViewerOptions) => ({ | ||
// name 可选,插件名称 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以用 ??= |
||
// 添加 webpack 插件 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这种注释不要 |
||
webpackConfig.plugins.push(new WebpackMockViewer(options)); | ||
} | ||
return webpackConfig; | ||
}); | ||
}, | ||
}); | ||
|
||
export default mockViewer; |
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"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个传入的是对象?