vite-plugin-blocklet 0.6.2 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +151 -6
- package/index.js +29 -3
- package/libs/config.js +5 -4
- package/libs/hmr.js +2 -1
- package/libs/loading.js +117 -0
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,8 @@ function toBlockletDid(name) {
|
|
|
37
37
|
|
|
38
38
|
const isInBlocklet = !!process.env.BLOCKLET_PORT;
|
|
39
39
|
|
|
40
|
-
function createHmrPlugin(
|
|
40
|
+
function createHmrPlugin(options = {}) {
|
|
41
|
+
const { version = vite.version } = options;
|
|
41
42
|
return {
|
|
42
43
|
name: 'blocklet:hmr',
|
|
43
44
|
apply: 'serve',
|
|
@@ -103,11 +104,12 @@ function createConfigPlugin() {
|
|
|
103
104
|
try {
|
|
104
105
|
const blockletYamlPath = './blocklet.yml';
|
|
105
106
|
const blockletYaml = YAML__default["default"].parse(fs__default["default"].readFileSync(blockletYamlPath, 'utf8'));
|
|
106
|
-
|
|
107
|
-
if (name) {
|
|
108
|
-
|
|
107
|
+
let { name, did } = blockletYaml;
|
|
108
|
+
if (!did && name) {
|
|
109
|
+
did = toBlockletDid(name);
|
|
110
|
+
}
|
|
111
|
+
if (did) {
|
|
109
112
|
const base = `/.blocklet/proxy/${did}/`;
|
|
110
|
-
|
|
111
113
|
return {
|
|
112
114
|
base,
|
|
113
115
|
};
|
|
@@ -157,6 +159,124 @@ function createMetaPlugin() {
|
|
|
157
159
|
};
|
|
158
160
|
}
|
|
159
161
|
|
|
162
|
+
/**
|
|
163
|
+
* @typedef {{
|
|
164
|
+
* color: string;
|
|
165
|
+
* image: string;
|
|
166
|
+
* }} GenerateOptions
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* @typedef {{
|
|
170
|
+
* loadingElementId?: string;
|
|
171
|
+
* loadingColor?: string;
|
|
172
|
+
* loadingImage?: string;
|
|
173
|
+
* }} LoadingPluginOptions
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
*
|
|
178
|
+
* @param {GenerateOptions} options
|
|
179
|
+
*/
|
|
180
|
+
function generateHtml({ color, image }) {
|
|
181
|
+
return `<style>
|
|
182
|
+
body,
|
|
183
|
+
html,
|
|
184
|
+
#app {
|
|
185
|
+
background: white;
|
|
186
|
+
width: 100%;
|
|
187
|
+
height: 100%;
|
|
188
|
+
display: flex;
|
|
189
|
+
flex-direction: column;
|
|
190
|
+
justify-content: center;
|
|
191
|
+
align-items: center;
|
|
192
|
+
margin: 0;
|
|
193
|
+
padding: 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.spinner {
|
|
197
|
+
width: 70px;
|
|
198
|
+
text-align: center;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.spinner > div {
|
|
202
|
+
width: 18px;
|
|
203
|
+
height: 18px;
|
|
204
|
+
background-color: ${color};
|
|
205
|
+
|
|
206
|
+
border-radius: 100%;
|
|
207
|
+
display: inline-block;
|
|
208
|
+
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
|
209
|
+
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.spinner .bounce1 {
|
|
213
|
+
-webkit-animation-delay: -0.32s;
|
|
214
|
+
animation-delay: -0.32s;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.spinner .bounce2 {
|
|
218
|
+
-webkit-animation-delay: -0.16s;
|
|
219
|
+
animation-delay: -0.16s;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@-webkit-keyframes sk-bouncedelay {
|
|
223
|
+
0%,
|
|
224
|
+
80%,
|
|
225
|
+
100% {
|
|
226
|
+
-webkit-transform: scale(0);
|
|
227
|
+
}
|
|
228
|
+
40% {
|
|
229
|
+
-webkit-transform: scale(1);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@keyframes sk-bouncedelay {
|
|
234
|
+
0%,
|
|
235
|
+
80%,
|
|
236
|
+
100% {
|
|
237
|
+
-webkit-transform: scale(0);
|
|
238
|
+
transform: scale(0);
|
|
239
|
+
}
|
|
240
|
+
40% {
|
|
241
|
+
-webkit-transform: scale(1);
|
|
242
|
+
transform: scale(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
</style>
|
|
246
|
+
|
|
247
|
+
<img src="${image}" width="90" height="90" style="margin-bottom: 30px" />
|
|
248
|
+
|
|
249
|
+
<div class="spinner">
|
|
250
|
+
<div class="bounce1"></div>
|
|
251
|
+
<div class="bounce2"></div>
|
|
252
|
+
<div class="bounce3"></div>
|
|
253
|
+
</div>`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
*
|
|
258
|
+
* @param {LoadingPluginOptions} options
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
function createLoadingPlugin({
|
|
262
|
+
loadingElementId = 'app',
|
|
263
|
+
loadingColor = '#8abaf0',
|
|
264
|
+
loadingImage = '/.well-known/service/blocklet/logo/',
|
|
265
|
+
} = {}) {
|
|
266
|
+
const injectHtml = generateHtml({
|
|
267
|
+
color: loadingColor,
|
|
268
|
+
image: loadingImage,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
name: 'blocklet:loading',
|
|
273
|
+
enforce: 'post',
|
|
274
|
+
transformIndexHtml(html) {
|
|
275
|
+
return html.replace(`<div id="${loadingElementId}"></div>`, `<div id="${loadingElementId}">${injectHtml}</div>`);
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
160
280
|
const argv = process.argv.slice(2);
|
|
161
281
|
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
162
282
|
|
|
@@ -188,6 +308,25 @@ async function setupClient(app, options = {}) {
|
|
|
188
308
|
}
|
|
189
309
|
}
|
|
190
310
|
|
|
311
|
+
/**
|
|
312
|
+
* @typedef {{
|
|
313
|
+
* disableNodePolyfills?: boolean;
|
|
314
|
+
* disableConfig?: boolean;
|
|
315
|
+
* disableMeta?: boolean;
|
|
316
|
+
* disableHmr?: boolean;
|
|
317
|
+
* disableLoading?: boolean;
|
|
318
|
+
*
|
|
319
|
+
* loadingElementId?: string;
|
|
320
|
+
* loadingColor?: string;
|
|
321
|
+
* loadingImage?: string;
|
|
322
|
+
* }} PluginOptions
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
*
|
|
327
|
+
* @param {PluginOptions} options
|
|
328
|
+
* @returns
|
|
329
|
+
*/
|
|
191
330
|
function createBlockletPlugin(options = {}) {
|
|
192
331
|
const {
|
|
193
332
|
// NOTICE: 由于 polyfill 不是每个项目都必须的,并且有些现有的项目已经配置了 polyfill,所以这个配置默认 disable 会比较好
|
|
@@ -196,6 +335,8 @@ function createBlockletPlugin(options = {}) {
|
|
|
196
335
|
disableConfig = false,
|
|
197
336
|
disableMeta = false,
|
|
198
337
|
disableHmr = false,
|
|
338
|
+
disableLoading = false,
|
|
339
|
+
...restOptions
|
|
199
340
|
} = options;
|
|
200
341
|
const plugins = [];
|
|
201
342
|
if (!disableMeta) {
|
|
@@ -205,11 +346,14 @@ function createBlockletPlugin(options = {}) {
|
|
|
205
346
|
plugins.push(createConfigPlugin());
|
|
206
347
|
}
|
|
207
348
|
if (!disableHmr) {
|
|
208
|
-
plugins.push(createHmrPlugin(
|
|
349
|
+
plugins.push(createHmrPlugin(restOptions));
|
|
209
350
|
}
|
|
210
351
|
if (!disableNodePolyfills) {
|
|
211
352
|
plugins.push(vitePluginNodePolyfills.nodePolyfills({ protocolImports: true }));
|
|
212
353
|
}
|
|
354
|
+
if (!disableLoading) {
|
|
355
|
+
plugins.push(createLoadingPlugin(restOptions));
|
|
356
|
+
}
|
|
213
357
|
|
|
214
358
|
return plugins;
|
|
215
359
|
}
|
|
@@ -220,6 +364,7 @@ Object.defineProperty(exports, 'nodePolyfills', {
|
|
|
220
364
|
});
|
|
221
365
|
exports.createBlockletConfig = createConfigPlugin;
|
|
222
366
|
exports.createBlockletHmr = createHmrPlugin;
|
|
367
|
+
exports.createBlockletLoading = createLoadingPlugin;
|
|
223
368
|
exports.createBlockletMeta = createMetaPlugin;
|
|
224
369
|
exports.createBlockletPlugin = createBlockletPlugin;
|
|
225
370
|
exports.setupClient = setupClient;
|
package/index.js
CHANGED
|
@@ -2,8 +2,28 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
|
2
2
|
import createHmrPlugin from './libs/hmr.js';
|
|
3
3
|
import createConfigPlugin from './libs/config.js';
|
|
4
4
|
import createMetaPlugin from './libs/meta.js';
|
|
5
|
+
import createLoadingPlugin from './libs/loading.js';
|
|
5
6
|
import setupClient from './libs/client.js';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {{
|
|
10
|
+
* disableNodePolyfills?: boolean;
|
|
11
|
+
* disableConfig?: boolean;
|
|
12
|
+
* disableMeta?: boolean;
|
|
13
|
+
* disableHmr?: boolean;
|
|
14
|
+
* disableLoading?: boolean;
|
|
15
|
+
*
|
|
16
|
+
* loadingElementId?: string;
|
|
17
|
+
* loadingColor?: string;
|
|
18
|
+
* loadingImage?: string;
|
|
19
|
+
* }} PluginOptions
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {PluginOptions} options
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
7
27
|
export function createBlockletPlugin(options = {}) {
|
|
8
28
|
const {
|
|
9
29
|
// NOTICE: 由于 polyfill 不是每个项目都必须的,并且有些现有的项目已经配置了 polyfill,所以这个配置默认 disable 会比较好
|
|
@@ -12,20 +32,25 @@ export function createBlockletPlugin(options = {}) {
|
|
|
12
32
|
disableConfig = false,
|
|
13
33
|
disableMeta = false,
|
|
14
34
|
disableHmr = false,
|
|
35
|
+
disableLoading = false,
|
|
36
|
+
...restOptions
|
|
15
37
|
} = options;
|
|
16
38
|
const plugins = [];
|
|
17
39
|
if (!disableMeta) {
|
|
18
|
-
plugins.push(createMetaPlugin(
|
|
40
|
+
plugins.push(createMetaPlugin(restOptions));
|
|
19
41
|
}
|
|
20
42
|
if (!disableConfig) {
|
|
21
|
-
plugins.push(createConfigPlugin(
|
|
43
|
+
plugins.push(createConfigPlugin(restOptions));
|
|
22
44
|
}
|
|
23
45
|
if (!disableHmr) {
|
|
24
|
-
plugins.push(createHmrPlugin(
|
|
46
|
+
plugins.push(createHmrPlugin(restOptions));
|
|
25
47
|
}
|
|
26
48
|
if (!disableNodePolyfills) {
|
|
27
49
|
plugins.push(nodePolyfills({ protocolImports: true }));
|
|
28
50
|
}
|
|
51
|
+
if (!disableLoading) {
|
|
52
|
+
plugins.push(createLoadingPlugin(restOptions));
|
|
53
|
+
}
|
|
29
54
|
|
|
30
55
|
return plugins;
|
|
31
56
|
}
|
|
@@ -35,5 +60,6 @@ export {
|
|
|
35
60
|
createHmrPlugin as createBlockletHmr,
|
|
36
61
|
createConfigPlugin as createBlockletConfig,
|
|
37
62
|
createMetaPlugin as createBlockletMeta,
|
|
63
|
+
createLoadingPlugin as createBlockletLoading,
|
|
38
64
|
nodePolyfills,
|
|
39
65
|
};
|
package/libs/config.js
CHANGED
|
@@ -48,11 +48,12 @@ export default function createConfigPlugin() {
|
|
|
48
48
|
try {
|
|
49
49
|
const blockletYamlPath = './blocklet.yml';
|
|
50
50
|
const blockletYaml = YAML.parse(fs.readFileSync(blockletYamlPath, 'utf8'));
|
|
51
|
-
|
|
52
|
-
if (name) {
|
|
53
|
-
|
|
51
|
+
let { name, did } = blockletYaml;
|
|
52
|
+
if (!did && name) {
|
|
53
|
+
did = toBlockletDid(name);
|
|
54
|
+
}
|
|
55
|
+
if (did) {
|
|
54
56
|
const base = `/.blocklet/proxy/${did}/`;
|
|
55
|
-
|
|
56
57
|
return {
|
|
57
58
|
base,
|
|
58
59
|
};
|
package/libs/hmr.js
CHANGED
|
@@ -2,7 +2,8 @@ import { version as viteVersion } from 'vite';
|
|
|
2
2
|
import semver from 'semver';
|
|
3
3
|
import { isInBlocklet } from './utils.js';
|
|
4
4
|
|
|
5
|
-
export default function createHmrPlugin(
|
|
5
|
+
export default function createHmrPlugin(options = {}) {
|
|
6
|
+
const { version = viteVersion } = options;
|
|
6
7
|
return {
|
|
7
8
|
name: 'blocklet:hmr',
|
|
8
9
|
apply: 'serve',
|
package/libs/loading.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {{
|
|
3
|
+
* color: string;
|
|
4
|
+
* image: string;
|
|
5
|
+
* }} GenerateOptions
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{
|
|
9
|
+
* loadingElementId?: string;
|
|
10
|
+
* loadingColor?: string;
|
|
11
|
+
* loadingImage?: string;
|
|
12
|
+
* }} LoadingPluginOptions
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {GenerateOptions} options
|
|
18
|
+
*/
|
|
19
|
+
function generateHtml({ color, image }) {
|
|
20
|
+
return `<style>
|
|
21
|
+
body,
|
|
22
|
+
html,
|
|
23
|
+
#app {
|
|
24
|
+
background: white;
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
align-items: center;
|
|
31
|
+
margin: 0;
|
|
32
|
+
padding: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.spinner {
|
|
36
|
+
width: 70px;
|
|
37
|
+
text-align: center;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.spinner > div {
|
|
41
|
+
width: 18px;
|
|
42
|
+
height: 18px;
|
|
43
|
+
background-color: ${color};
|
|
44
|
+
|
|
45
|
+
border-radius: 100%;
|
|
46
|
+
display: inline-block;
|
|
47
|
+
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
|
48
|
+
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.spinner .bounce1 {
|
|
52
|
+
-webkit-animation-delay: -0.32s;
|
|
53
|
+
animation-delay: -0.32s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.spinner .bounce2 {
|
|
57
|
+
-webkit-animation-delay: -0.16s;
|
|
58
|
+
animation-delay: -0.16s;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@-webkit-keyframes sk-bouncedelay {
|
|
62
|
+
0%,
|
|
63
|
+
80%,
|
|
64
|
+
100% {
|
|
65
|
+
-webkit-transform: scale(0);
|
|
66
|
+
}
|
|
67
|
+
40% {
|
|
68
|
+
-webkit-transform: scale(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@keyframes sk-bouncedelay {
|
|
73
|
+
0%,
|
|
74
|
+
80%,
|
|
75
|
+
100% {
|
|
76
|
+
-webkit-transform: scale(0);
|
|
77
|
+
transform: scale(0);
|
|
78
|
+
}
|
|
79
|
+
40% {
|
|
80
|
+
-webkit-transform: scale(1);
|
|
81
|
+
transform: scale(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
</style>
|
|
85
|
+
|
|
86
|
+
<img src="${image}" width="90" height="90" style="margin-bottom: 30px" />
|
|
87
|
+
|
|
88
|
+
<div class="spinner">
|
|
89
|
+
<div class="bounce1"></div>
|
|
90
|
+
<div class="bounce2"></div>
|
|
91
|
+
<div class="bounce3"></div>
|
|
92
|
+
</div>`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param {LoadingPluginOptions} options
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
export default function createLoadingPlugin({
|
|
101
|
+
loadingElementId = 'app',
|
|
102
|
+
loadingColor = '#8abaf0',
|
|
103
|
+
loadingImage = '/.well-known/service/blocklet/logo/',
|
|
104
|
+
} = {}) {
|
|
105
|
+
const injectHtml = generateHtml({
|
|
106
|
+
color: loadingColor,
|
|
107
|
+
image: loadingImage,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
name: 'blocklet:loading',
|
|
112
|
+
enforce: 'post',
|
|
113
|
+
transformIndexHtml(html) {
|
|
114
|
+
return html.replace(`<div id="${loadingElementId}"></div>`, `<div id="${loadingElementId}">${injectHtml}</div>`);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-blocklet",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.5",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"rollup": "^2.79.1"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@arcblock/did": "^1.18.
|
|
31
|
-
"@ocap/mcrypto": "^1.18.
|
|
32
|
-
"@ocap/util": "^1.18.
|
|
30
|
+
"@arcblock/did": "^1.18.78",
|
|
31
|
+
"@ocap/mcrypto": "^1.18.78",
|
|
32
|
+
"@ocap/util": "^1.18.78",
|
|
33
33
|
"get-port": "^5.1.1",
|
|
34
34
|
"mri": "^1.2.0",
|
|
35
35
|
"semver": "^7.5.0",
|