Skip to content

Commit dfa610e

Browse files
committed
feat: merge poi plugin
1 parent f779172 commit dfa610e

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

poi.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const LoadingScreenPlugin = require('.')
2+
const colors = require('@poi/dev-utils/colors')
3+
4+
exports.name = 'loading-screen'
5+
6+
exports.when = api => api.args.has('s') || api.args.has('serve')
7+
8+
exports.apply = api => {
9+
/**
10+
* Prepare arguments for open browser
11+
*/
12+
const { args, config } = api
13+
const { host, port } = config.devServer
14+
const isUnspecifiedHost = host === '0.0.0.0' || host === '::'
15+
const prettyHost = isUnspecifiedHost ? 'localhost' : host
16+
17+
/**
18+
* Make poi lose ability to open browser
19+
*/
20+
delete config.devServer.open
21+
22+
console.log()
23+
console.log('You can now view your app in the browser:')
24+
console.log(`Local: http://${prettyHost}:${colors.bold(port)}`)
25+
console.log()
26+
27+
/**
28+
* Override poi progress plugin
29+
*/
30+
api.hook('createWebpackChain', config => {
31+
config.plugin('progress').init(
32+
(_, [handler]) =>
33+
new LoadingScreenPlugin({
34+
logo:
35+
'https://camo.githubusercontent.com/5ae09d1630be8e50dd69a50d9d45b326a0cb41ab/68747470733a2f2f692e6c6f6c692e6e65742f323031382f30392f31322f356239386537373335326339642e706e67',
36+
handler,
37+
port,
38+
// Real • open browser
39+
callback() {
40+
if (args.has('o') || args.has('open')) {
41+
require('@poi/dev-utils/openBrowser')(
42+
`http://${prettyHost}:${port}`
43+
)
44+
}
45+
}
46+
})
47+
)
48+
})
49+
}

0 commit comments

Comments
 (0)