Skip to content

Commit 6df480d

Browse files
author
chengyu.chengyulia
committed
feat: add disableDashboard config
1 parent e23f627 commit 6df480d

2 files changed

Lines changed: 124 additions & 116 deletions

File tree

src/built-in-plugins/command-dev/plugin/project-dev.ts

Lines changed: 119 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -101,45 +101,46 @@ async function debugProject(options?: any) {
101101

102102
await bundleDlls({ dllOutPath, dllFileName, dllMainfestName });
103103

104-
// Bundle dashboard if plugins changed or dashboard bundle not exist.
105-
const dashboardDistDir = path.join(pri.projectRootPath, tempPath.dir, 'static/dashboard-bundle');
106-
if (!fs.existsSync(path.join(dashboardDistDir, `${dashboardBundleFileName}.js`))) {
107-
const dashboardEntryFilePath = createDashboardEntry();
108-
109-
const status = await runWebpack({
110-
mode: 'production',
111-
publicPath: '/bundle/',
112-
entryPath: dashboardEntryFilePath,
113-
distDir: dashboardDistDir,
114-
outFileName: 'main.[hash].js', // dashboard has no css file
115-
pipeConfig,
116-
});
117-
projectState.set('dashboardHash', status.hash);
118-
}
119-
const stdoutOfAnyType = process.stdout as any;
120-
try {
121-
stdoutOfAnyType.clearLine(0);
122-
} catch {
123-
//
104+
if (globalState.sourceConfig.useHttps) {
105+
logInfo('you should set chrome://flags/#allow-insecure-localhost, to trust local certificate.');
124106
}
125107

126-
logInfo('\nStart dev server.\n');
108+
if (!pri.sourceConfig.disableDashboard) {
109+
// Bundle dashboard if plugins changed or dashboard bundle not exist.
110+
const dashboardDistDir = path.join(pri.projectRootPath, tempPath.dir, 'static/dashboard-bundle');
111+
if (!fs.existsSync(path.join(dashboardDistDir, `${dashboardBundleFileName}.js`))) {
112+
const dashboardEntryFilePath = createDashboardEntry();
113+
114+
const status = await runWebpack({
115+
mode: 'production',
116+
publicPath: '/bundle/',
117+
entryPath: dashboardEntryFilePath,
118+
distDir: dashboardDistDir,
119+
outFileName: 'main.[hash].js', // dashboard has no css file
120+
pipeConfig,
121+
});
122+
projectState.set('dashboardHash', status.hash);
123+
}
124+
const stdoutOfAnyType = process.stdout as any;
125+
try {
126+
stdoutOfAnyType.clearLine(0);
127+
} catch {
128+
//
129+
}
127130

128-
// Start dashboard server
129-
dashboardServer({ serverPort: dashboardServerPort, analyseInfo });
131+
logInfo('\nStart dev server.\n');
130132

131-
if (globalState.sourceConfig.useHttps) {
132-
logInfo('you should set chrome://flags/#allow-insecure-localhost, to trust local certificate.');
133+
// Start dashboard server
134+
dashboardServer({ serverPort: dashboardServerPort, analyseInfo });
135+
// Start dashboard client production server
136+
dashboardClientServer({
137+
serverPort: dashboardServerPort,
138+
clientPort: dashboardClientPort,
139+
staticRootPath: path.join(pri.projectRootPath, tempPath.dir, 'static'),
140+
hash: projectState.get('dashboardHash'),
141+
});
133142
}
134143

135-
// Start dashboard client production server
136-
dashboardClientServer({
137-
serverPort: dashboardServerPort,
138-
clientPort: dashboardClientPort,
139-
staticRootPath: path.join(pri.projectRootPath, tempPath.dir, 'static'),
140-
hash: projectState.get('dashboardHash'),
141-
});
142-
143144
// Serve project
144145
await runWebpackDevServer({
145146
mode: options?.mode ?? 'development',
@@ -215,95 +216,97 @@ function debugProjectPrepare(dashboardClientPort: number) {
215216
});
216217

217218
// Load webui iframe
218-
entry.pipeEntryRender(str => {
219-
return `
220-
${str}
221-
const webUICss = \`
222-
#pri-help-button {
223-
position: fixed;
224-
display: flex;
225-
justify-content: center;
226-
align-items: center;
227-
width: 140px;
228-
height: 30px;
229-
transform: rotate(90deg);
230-
font-size: 14px;
231-
right: -55px;
232-
top: calc(50% - 15px);
233-
border: 1px solid #ddd;
234-
border-top: none;
235-
border-bottom-left-radius: 5px;
236-
border-bottom-right-radius: 5px;
237-
color: #666;
238-
z-index: 10001;
239-
cursor: pointer;
240-
transition: all .2s;
241-
background-color: white;
242-
user-select: none;
243-
}
219+
if (!pri.sourceConfig.disableDashboard) {
220+
entry.pipeEntryRender(str => {
221+
return `
222+
${str}
223+
const webUICss = \`
224+
#pri-help-button {
225+
position: fixed;
226+
display: flex;
227+
justify-content: center;
228+
align-items: center;
229+
width: 140px;
230+
height: 30px;
231+
transform: rotate(90deg);
232+
font-size: 14px;
233+
right: -55px;
234+
top: calc(50% - 15px);
235+
border: 1px solid #ddd;
236+
border-top: none;
237+
border-bottom-left-radius: 5px;
238+
border-bottom-right-radius: 5px;
239+
color: #666;
240+
z-index: 10001;
241+
cursor: pointer;
242+
transition: all .2s;
243+
background-color: white;
244+
user-select: none;
245+
}
244246
245-
#pri-help-button.active {
246-
right: 744px !important;
247-
}
247+
#pri-help-button.active {
248+
right: 744px !important;
249+
}
248250
249-
#pri-help-button:hover {
250-
color: black;
251-
}
251+
#pri-help-button:hover {
252+
color: black;
253+
}
252254
253-
#pri-help-iframe {
254-
position: fixed;
255-
right: -810px;
256-
z-index: 10000;
257-
background-color: white;
258-
width: 800px;
259-
top: 0;
260-
height: 100%;
261-
border: 0;
262-
outline: 0;
263-
box-shadow: -1px 0 1px #d4d4d4;
264-
transition: right .2s;
265-
}
255+
#pri-help-iframe {
256+
position: fixed;
257+
right: -810px;
258+
z-index: 10000;
259+
background-color: white;
260+
width: 800px;
261+
top: 0;
262+
height: 100%;
263+
border: 0;
264+
outline: 0;
265+
box-shadow: -1px 0 1px #d4d4d4;
266+
transition: right .2s;
267+
}
266268
267-
#pri-help-iframe.active {
268-
right: 0 !important;
269-
}
270-
\`
271-
const webUIStyle = document.createElement('style')
272-
273-
webUIStyle.type = "text/css"
274-
if ((webUIStyle as any).styleSheet){
275-
(webUIStyle as any).styleSheet.cssText = webUICss
276-
} else {
277-
webUIStyle.appendChild(document.createTextNode(webUICss))
278-
}
279-
280-
document.head.appendChild(webUIStyle)
281-
282-
// Add dashboard iframe
283-
const dashboardIframe = document.createElement("iframe")
284-
dashboardIframe.id = "pri-help-iframe"
285-
dashboardIframe.src = "//${pri.sourceConfig.host}:${dashboardClientPort}"
286-
document.body.appendChild(dashboardIframe)
287-
288-
// Add dashboard button
289-
const dashboardButton = document.createElement("div")
290-
dashboardButton.id = "pri-help-button"
291-
dashboardButton.innerText = "Toggle dashboard"
292-
dashboardButton.onclick = () => {
293-
const activeClassName = "active"
294-
const isShow = dashboardIframe.classList.contains(activeClassName)
295-
296-
if (isShow) {
297-
dashboardIframe.classList.remove(activeClassName)
298-
dashboardButton.classList.remove(activeClassName)
269+
#pri-help-iframe.active {
270+
right: 0 !important;
271+
}
272+
\`
273+
const webUIStyle = document.createElement('style')
274+
275+
webUIStyle.type = "text/css"
276+
if ((webUIStyle as any).styleSheet){
277+
(webUIStyle as any).styleSheet.cssText = webUICss
299278
} else {
300-
dashboardIframe.classList.add(activeClassName)
301-
dashboardButton.classList.add(activeClassName)
279+
webUIStyle.appendChild(document.createTextNode(webUICss))
302280
}
303-
}
304-
document.body.appendChild(dashboardButton)
305-
`;
306-
});
281+
282+
document.head.appendChild(webUIStyle)
283+
284+
// Add dashboard iframe
285+
const dashboardIframe = document.createElement("iframe")
286+
dashboardIframe.id = "pri-help-iframe"
287+
dashboardIframe.src = "//${pri.sourceConfig.host}:${dashboardClientPort}"
288+
document.body.appendChild(dashboardIframe)
289+
290+
// Add dashboard button
291+
const dashboardButton = document.createElement("div")
292+
dashboardButton.id = "pri-help-button"
293+
dashboardButton.innerText = "Toggle dashboard"
294+
dashboardButton.onclick = () => {
295+
const activeClassName = "active"
296+
const isShow = dashboardIframe.classList.contains(activeClassName)
297+
298+
if (isShow) {
299+
dashboardIframe.classList.remove(activeClassName)
300+
dashboardButton.classList.remove(activeClassName)
301+
} else {
302+
dashboardIframe.classList.add(activeClassName)
303+
dashboardButton.classList.add(activeClassName)
304+
}
305+
}
306+
document.body.appendChild(dashboardButton)
307+
`;
308+
});
309+
}
307310
}
308311
});
309312

src/utils/define.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ export class ProjectConfig {
347347
* Unnecessarily published packages, only take effect when includeAll is true.
348348
*/
349349
public unPublishList?: string[] = [];
350+
351+
/**
352+
* Disable dashboard ui
353+
*/
354+
public disableDashboard: boolean;
350355
}
351356

352357
export type SetPipe = (pipeName: string, callback: PipeCallback) => void;

0 commit comments

Comments
 (0)