vite-plugin-blocklet 0.5.9 → 0.5.11
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/README.md +58 -0
- package/dist/index.cjs +10 -1
- package/libs/client.js +9 -1
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# vite-plugi-blocklet
|
|
2
|
+
|
|
3
|
+
The Vite library plugin, which enhanced development of [ArcBlock blocklet](http://developer.blocklet.io/)
|
|
4
|
+
|
|
5
|
+
## Use examples
|
|
6
|
+
|
|
7
|
+
### Example of front-end project
|
|
8
|
+
``` js
|
|
9
|
+
import { defineConfig } from 'vite';
|
|
10
|
+
import react from '@vitejs/plugin-react';
|
|
11
|
+
import { createBlockletPlugin } from 'vite-plugin-blocklet';
|
|
12
|
+
|
|
13
|
+
// https://vitejs.dev/config/
|
|
14
|
+
export default defineConfig(async () => {
|
|
15
|
+
return {
|
|
16
|
+
plugins: [react(), createBlockletPlugin()],
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Example of back-end project
|
|
22
|
+
|
|
23
|
+
`api/index.js`
|
|
24
|
+
```js
|
|
25
|
+
const express = require('express');
|
|
26
|
+
const app = express();
|
|
27
|
+
|
|
28
|
+
module.exports = { app };
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`api/dev.js`
|
|
32
|
+
```js
|
|
33
|
+
const { setupClient } = require('vite-plugin-blocklet');
|
|
34
|
+
const { app } = require('./index');
|
|
35
|
+
|
|
36
|
+
setupClient(app);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`package.json`
|
|
40
|
+
```json
|
|
41
|
+
"start": "NODE_ENV=development nodemon api/dev.js -w api",
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Basically, you `vite.config.js` file should be in the root of project folders, if you need setup a custom vite config file, you should change your npm scripts, like:
|
|
45
|
+
|
|
46
|
+
`package.json`
|
|
47
|
+
```json
|
|
48
|
+
"start": "NODE_ENV=development nodemon api/dev.js -w api -- --config=./config/vite.config.js",
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or you can just pass vite config file path to `setupClient` function, like this:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const { setupClient } = require('vite-plugin-blocklet');
|
|
55
|
+
const { app } = require('./index');
|
|
56
|
+
|
|
57
|
+
setupClient(app, { configFile: './config/vite.config.js'});
|
|
58
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ var fs = require('fs');
|
|
|
11
11
|
var path = require('path');
|
|
12
12
|
var YAML = require('yaml');
|
|
13
13
|
var getPort = require('get-port');
|
|
14
|
+
var mri = require('mri');
|
|
14
15
|
|
|
15
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
17
|
|
|
@@ -20,6 +21,7 @@ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
|
20
21
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
21
22
|
var YAML__default = /*#__PURE__*/_interopDefaultLegacy(YAML);
|
|
22
23
|
var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
|
|
24
|
+
var mri__default = /*#__PURE__*/_interopDefaultLegacy(mri);
|
|
23
25
|
|
|
24
26
|
const { types } = Mcrypto__default["default"];
|
|
25
27
|
|
|
@@ -150,14 +152,21 @@ function createMetaPlugin() {
|
|
|
150
152
|
};
|
|
151
153
|
}
|
|
152
154
|
|
|
155
|
+
const argv = process.argv.slice(2);
|
|
153
156
|
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
154
157
|
|
|
155
158
|
async function setupClient(app, options = {}) {
|
|
156
159
|
if (!isProduction) {
|
|
157
|
-
const
|
|
160
|
+
const params = mri__default["default"](argv, {
|
|
161
|
+
alias: {
|
|
162
|
+
config: 'c',
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const { host = '127.0.0.1', protocol = 'ws', port: inputPort, configFile = '' } = options;
|
|
158
166
|
const port = await getPort__default["default"]({ port: inputPort });
|
|
159
167
|
// 以中间件模式创建 Vite 服务器
|
|
160
168
|
const vite$1 = await vite.createServer({
|
|
169
|
+
configFile: params.config || configFile || undefined,
|
|
161
170
|
server: {
|
|
162
171
|
middlewareMode: true,
|
|
163
172
|
hmr: {
|
package/libs/client.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import getPort from 'get-port';
|
|
2
2
|
import { createServer } from 'vite';
|
|
3
|
+
import mri from 'mri';
|
|
3
4
|
|
|
5
|
+
const argv = process.argv.slice(2);
|
|
4
6
|
const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
|
|
5
7
|
|
|
6
8
|
export default async function setupClient(app, options = {}) {
|
|
7
9
|
if (!isProduction) {
|
|
8
|
-
const
|
|
10
|
+
const params = mri(argv, {
|
|
11
|
+
alias: {
|
|
12
|
+
config: 'c',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const { host = '127.0.0.1', protocol = 'ws', port: inputPort, configFile = '' } = options;
|
|
9
16
|
const port = await getPort({ port: inputPort });
|
|
10
17
|
// 以中间件模式创建 Vite 服务器
|
|
11
18
|
const vite = await createServer({
|
|
19
|
+
configFile: params.config || configFile || undefined,
|
|
12
20
|
server: {
|
|
13
21
|
middlewareMode: true,
|
|
14
22
|
hmr: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-blocklet",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.11",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@ocap/mcrypto": "^1.18.31",
|
|
32
32
|
"@ocap/util": "^1.18.31",
|
|
33
33
|
"get-port": "^5.1.1",
|
|
34
|
+
"mri": "^1.2.0",
|
|
34
35
|
"semver": "^7.3.8",
|
|
35
36
|
"yaml": "^2.1.3"
|
|
36
37
|
},
|