Skip to content

Commit 29cfedc

Browse files
authored
feat: support show percent while loading app (#6)
* fix: should be `development` mode by default * chore(readme): tweak * feat: support show percent while loading app close #3
1 parent 86d6d15 commit 29cfedc

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Or with regular HTML:
8282

8383
```js
8484
new LoadingScreenPlugin({
85-
logo: '<svg xmlns>...</svg>'
85+
logo: '<div>my logo</div>'
8686
})
8787
```
8888

@@ -122,6 +122,11 @@ Progress hooks report details.
122122

123123
Reference: https://webpack.js.org/plugins/progress-plugin/
124124

125+
### showPercent
126+
127+
- Type: `boolean`
128+
- Default: `true`
129+
125130
## Credits
126131

127132
- [**nuxt/loading-screen**](https://github.com/nuxt/loading-screen)

app/app.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
<div class="progress_bar_container">
2424
<div class="progress_bar" :style="{ width: `${states[bundle].progress}%`, backgroundColor: theme[bundle] }" />
2525
</div>
26-
<h4>{{ states[bundle].status }}</h4>
26+
<div class="progress_status_container">
27+
<h4>{{ states[bundle].status }}</h4>
28+
<h4 v-if="theme.showPercent">{{ states[bundle].progress }}%</h4>
29+
</div>
2730
</div>
2831
</transition-group>
2932
</div>

app/css/loading.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ h4 {
7676
width: 10px;
7777
transition: width 0.4s;
7878
}
79+
80+
.progress_status_container {
81+
display: flex;
82+
justify-content: space-between;
83+
}

lib/loading.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class LoadingUI {
1212
this.baseURL = opts.baseURL
1313

1414
this.logo = opts.logo
15-
this.theme = opts.theme
15+
this.theme = Object.assign(opts.theme, {
16+
showPercent: opts.showPercent
17+
})
1618

1719
this.serveIndex = this.serveIndex.bind(this)
1820
this.serveWS = this.serveWS.bind(this)

lib/plugin.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@ const { ProgressPlugin: Plugin } = require('webpack')
55
module.exports = class ProgressPlugin extends Plugin {
66
constructor(opts = {}) {
77
super()
8+
this.env = opts.env || process.env.NODE_ENV || 'development'
9+
10+
this.isProd = this.env === 'production'
11+
812
this.opts = Object.assign(
913
{
1014
baseURL: '/',
1115
logo: 'https://webpack.js.org/assets/icon-square-big.svg',
1216
host: 'localhost',
1317
port: process.env.port || 4000,
1418
callback: () => {
19+
if (this.isProd) return
1520
console.log(`[loading screen]: http://localhost:${this.opts.port}`)
1621
},
1722
theme: {
1823
client: '#8ed5fb',
1924
server: '#1b78bf',
2025
modern: '#2f495e'
21-
}
26+
},
27+
showPercent: true
2228
},
2329
opts
2430
)
2531

26-
this.env = opts.env || process.env.NODE_ENV
27-
2832
this.connections = new Set()
2933

3034
this.handler = (per, message, ...details) => {
@@ -47,10 +51,6 @@ module.exports = class ProgressPlugin extends Plugin {
4751
}
4852

4953
async init() {
50-
if (this.env !== 'development') {
51-
return
52-
}
53-
5454
const LoadingUI = require('./loading')
5555
this.loading = new LoadingUI(this.opts)
5656

0 commit comments

Comments
 (0)