create-blocklet 0.4.70 → 0.4.72

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.
Files changed (41) hide show
  1. package/common/{_editorconfig → .editorconfig} +0 -0
  2. package/common/{_prettierrc → .prettierrc} +0 -0
  3. package/index.js +7 -17
  4. package/package.json +1 -1
  5. package/templates/react-dapp/.env +1 -1
  6. package/templates/react-dapp/api/index.js +1 -1
  7. package/templates/react-dapp/blocklet.yml +2 -2
  8. package/templates/react-dapp/index.html +16 -0
  9. package/templates/react-dapp/package.json +8 -5
  10. package/templates/react-dapp/src/index.jsx +1 -1
  11. package/templates/react-dapp/vite.config.js +36 -0
  12. package/templates/react-gun-dapp/.env +1 -1
  13. package/templates/react-gun-dapp/api/index.js +1 -1
  14. package/templates/react-gun-dapp/blocklet.yml +2 -2
  15. package/templates/react-gun-dapp/index.html +16 -0
  16. package/templates/react-gun-dapp/package.json +8 -5
  17. package/templates/react-gun-dapp/src/index.jsx +1 -1
  18. package/templates/react-gun-dapp/src/pages/home.jsx +1 -1
  19. package/templates/react-gun-dapp/vite.config.js +41 -0
  20. package/templates/react-static/.env +1 -1
  21. package/templates/react-static/blocklet.yml +1 -1
  22. package/templates/react-static/index.html +16 -0
  23. package/templates/react-static/package.json +9 -5
  24. package/templates/react-static/src/index.jsx +1 -1
  25. package/templates/react-static/vite.config.js +26 -0
  26. package/templates/solidjs-dapp/package.json +1 -1
  27. package/templates/solidjs-static/package.json +1 -1
  28. package/templates/svelte-dapp/package.json +1 -1
  29. package/templates/svelte-static/package.json +1 -1
  30. package/templates/vue-dapp/package.json +1 -1
  31. package/templates/vue-dapp/vite.config.js +5 -1
  32. package/templates/vue-static/package.json +1 -1
  33. package/templates/vue2-dapp/vue.config.js +4 -4
  34. package/common/_gitignore +0 -28
  35. package/common/_npmrc +0 -3
  36. package/templates/react-dapp/craco.config.js +0 -39
  37. package/templates/react-dapp/public/index.html +0 -35
  38. package/templates/react-gun-dapp/craco.config.js +0 -41
  39. package/templates/react-gun-dapp/public/index.html +0 -35
  40. package/templates/react-static/craco.config.js +0 -28
  41. package/templates/react-static/public/index.html +0 -35
File without changes
File without changes
package/index.js CHANGED
@@ -16,7 +16,6 @@ import { checkServerInstalled, checkServerRunning, checkSatisfiedVersion, getSer
16
16
  import { toBlockletDid } from './lib/did.js';
17
17
  import { initGitRepo } from './lib/git.js';
18
18
  import {
19
- copy,
20
19
  emptyDir,
21
20
  isEmpty,
22
21
  isValidPackageName,
@@ -115,12 +114,7 @@ const templates = [
115
114
  },
116
115
  ];
117
116
 
118
- const renameFiles = {
119
- _gitignore: '.gitignore',
120
- _npmrc: '.npmrc',
121
- _editorconfig: '.editorconfig',
122
- _prettierrc: '.prettierrc',
123
- };
117
+
124
118
 
125
119
  async function init() {
126
120
  const { version } = await fs.readJSONSync(path.resolve(__dirname, 'package.json'));
@@ -266,7 +260,7 @@ async function init() {
266
260
  if (mainBlocklet) {
267
261
  await checkLerna();
268
262
  await checkYarn();
269
- copy(path.join(__dirname, 'templates', 'monorepo'), root);
263
+ fs.copySync(path.join(__dirname, 'templates', 'monorepo'), root);
270
264
  }
271
265
 
272
266
  for (const templateName of templateNames) {
@@ -279,7 +273,7 @@ async function init() {
279
273
  const commonFiles = fs.readdirSync(commonDir);
280
274
  for (const file of commonFiles) {
281
275
  // 如果选择多个模板,每个子 package 中 只会包含必要的 文件
282
- if (mainBlocklet && !['screenshots', 'public', 'logo.png', '_prettierrc'].includes(file)) {
276
+ if (mainBlocklet && !['screenshots', 'public', 'logo.png', '.prettierrc'].includes(file)) {
283
277
  continue;
284
278
  }
285
279
  // xmark 相关的模板不添加 .husky
@@ -287,11 +281,9 @@ async function init() {
287
281
  // eslint-disable-next-line no-continue
288
282
  continue;
289
283
  }
290
- const targetPath = renameFiles[file]
291
- ? path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', renameFiles[file])
292
- : path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
284
+ const targetPath = path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
293
285
 
294
- copy(path.join(commonDir, file), targetPath);
286
+ fs.copySync(path.join(commonDir, file), targetPath);
295
287
  }
296
288
  })();
297
289
 
@@ -518,13 +510,11 @@ async function init() {
518
510
 
519
511
  // inside functions
520
512
  function write(file, content, templateDir, templateName) {
521
- const targetPath = renameFiles[file]
522
- ? path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', renameFiles[file])
523
- : path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
513
+ const targetPath = path.join(root, mainBlocklet ? `blocklets/${templateName}` : '', file);
524
514
  if (content) {
525
515
  fs.writeFileSync(targetPath, content);
526
516
  } else {
527
- copy(path.join(templateDir, file), targetPath);
517
+ fs.copySync(path.join(templateDir, file), targetPath);
528
518
  }
529
519
  }
530
520
  function read(file, templateName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-blocklet",
3
- "version": "0.4.70",
3
+ "version": "0.4.72",
4
4
  "exports": "./index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:blocklet/create-blocklet.git",
@@ -1,2 +1,2 @@
1
1
  GENERATE_SOURCEMAP=false
2
- REACT_APP_TITLE=''
2
+ APP_TITLE=''
@@ -27,7 +27,7 @@ if (isProduction) {
27
27
  app.use(cors());
28
28
  app.use(compression());
29
29
 
30
- const staticDir = path.resolve(process.env.BLOCKLET_APP_DIR, 'build');
30
+ const staticDir = path.resolve(process.env.BLOCKLET_APP_DIR, 'dist');
31
31
  app.use(express.static(staticDir, { maxAge: '30d', index: false }));
32
32
  app.use(router);
33
33
  app.use(fallback('index.html', { root: staticDir }));
@@ -1,4 +1,4 @@
1
- name: template-react
1
+ name: template-react-dapp
2
2
  title: Blocklet Template React
3
3
  description: A Blocklet DAPP blocklet
4
4
  keywords:
@@ -17,7 +17,7 @@ specVersion: 1.1.1
17
17
  version: 0.1.0
18
18
  logo: logo.png
19
19
  files:
20
- - build
20
+ - dist
21
21
  - logo.png
22
22
  - screenshots
23
23
  - api/hooks/pre-start.js
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
7
+ <meta name="theme-color" content="#4F6AF5" />
8
+ <meta name="description" content="Web site created using create-blocklet" />
9
+ <title><%- title %></title>
10
+ </head>
11
+ <body>
12
+ <noscript> You need to enable JavaScript to run this app. </noscript>
13
+ <div id="app"></div>
14
+ <script type="module" src="/src/index.jsx"></script>
15
+ </body>
16
+ </html>
@@ -3,15 +3,15 @@
3
3
  "version": "0.1.0",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev",
6
- "eject": "react-scripts eject",
6
+ "eject": "vite eject",
7
7
  "lint": "eslint src api --ext .mjs,.js,.jsx,.ts,.tsx",
8
8
  "lint:fix": "npm run lint -- --fix",
9
9
  "start": "npm-run-all --parallel start:*",
10
- "start:client": "craco start",
10
+ "start:client": "vite --host",
11
11
  "start:api": "NODE_ENV=development nodemon api/index.js -w api",
12
12
  "clean": "rm -rf .blocklet",
13
13
  "bundle": "npm run bundle:client && npm run bundle:api",
14
- "bundle:client": "PUBLIC_URL='/.blocklet/proxy/<%= did %>' craco build",
14
+ "bundle:client": "vite build",
15
15
  "bundle:api": "npm run clean && blocklet bundle --zip --create-release",
16
16
  "deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
17
17
  "upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@arcblock/eslint-config": "^0.2.3",
64
- "@craco/craco": "^6.4.5",
64
+ "@vitejs/plugin-react": "^2.1.0",
65
65
  "eslint": "^8.25.0",
66
66
  "husky": "^8.0.1",
67
67
  "lint-staged": "^12.5.0",
@@ -69,6 +69,9 @@
69
69
  "nodemon": "^2.0.20",
70
70
  "npm-run-all": "^4.1.5",
71
71
  "prettier": "^2.7.1",
72
- "react-scripts": "5.0.1"
72
+ "vite": "^3.1.7",
73
+ "vite-plugin-blocklet": "^0.4.72",
74
+ "vite-plugin-html": "^3.2.0",
75
+ "vite-plugin-svgr": "^2.2.1"
73
76
  }
74
77
  }
@@ -1,5 +1,5 @@
1
1
  import ReactDOM from 'react-dom/client';
2
2
  import App from './app';
3
3
 
4
- const root = ReactDOM.createRoot(document.getElementById('root'));
4
+ const root = ReactDOM.createRoot(document.getElementById('app'));
5
5
  root.render(<App />);
@@ -0,0 +1,36 @@
1
+ import { defineConfig, loadEnv } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import { createHtmlPlugin } from 'vite-plugin-html';
4
+ import { createBlockletPlugin } from 'vite-plugin-blocklet';
5
+ import svgr from 'vite-plugin-svgr';
6
+
7
+ // https://vitejs.dev/config/
8
+ export default defineConfig(async ({ mode }) => {
9
+ const envMap = loadEnv(mode, process.cwd(), '');
10
+ const apiPort = envMap.API_PORT || 3030;
11
+ const apiPrefix = `${process.env.BLOCKLET_DEV_MOUNT_POINT || ''}/api`;
12
+
13
+ return {
14
+ plugins: [
15
+ react(),
16
+ createHtmlPlugin({
17
+ minify: true,
18
+ inject: {
19
+ data: {
20
+ title: envMap.APP_TITLE,
21
+ },
22
+ },
23
+ }),
24
+ createBlockletPlugin(),
25
+ svgr(),
26
+ ],
27
+ server: {
28
+ proxy: {
29
+ [apiPrefix]: {
30
+ target: `http://127.0.0.1:${apiPort}`,
31
+ rewrite: (path) => path.replace(apiPrefix, '/api'), // rewrite path when blocklet dev
32
+ },
33
+ },
34
+ },
35
+ };
36
+ });
@@ -1,2 +1,2 @@
1
1
  GENERATE_SOURCEMAP=false
2
- REACT_APP_TITLE=''
2
+ APP_TITLE=''
@@ -32,7 +32,7 @@ if (isProduction) {
32
32
  app.use(cors());
33
33
  app.use(compression());
34
34
 
35
- const staticDir = path.resolve(process.env.BLOCKLET_APP_DIR, 'build');
35
+ const staticDir = path.resolve(process.env.BLOCKLET_APP_DIR, 'dist');
36
36
  app.use(express.static(staticDir, { maxAge: '30d', index: false }));
37
37
  app.use(router);
38
38
  app.use(fallback('index.html', { root: staticDir }));
@@ -1,4 +1,4 @@
1
- name: template-react
1
+ name: template-react-gunjs
2
2
  title: Blocklet Template React
3
3
  description: A Blocklet DAPP blocklet
4
4
  keywords:
@@ -17,7 +17,7 @@ specVersion: 1.1.1
17
17
  version: 0.1.0
18
18
  logo: logo.png
19
19
  files:
20
- - build
20
+ - dist
21
21
  - logo.png
22
22
  - screenshots
23
23
  - api/hooks/pre-start.js
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
7
+ <meta name="theme-color" content="#4F6AF5" />
8
+ <meta name="description" content="Web site created using create-blocklet" />
9
+ <title><%- title %></title>
10
+ </head>
11
+ <body>
12
+ <noscript> You need to enable JavaScript to run this app. </noscript>
13
+ <div id="app"></div>
14
+ <script type="module" src="/src/index.jsx"></script>
15
+ </body>
16
+ </html>
@@ -3,15 +3,15 @@
3
3
  "version": "0.1.0",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev",
6
- "eject": "react-scripts eject",
6
+ "eject": "vite eject",
7
7
  "lint": "eslint src api --ext .mjs,.js,.jsx,.ts,.tsx",
8
8
  "lint:fix": "npm run lint -- --fix",
9
9
  "start": "npm-run-all --parallel start:*",
10
- "start:client": "craco start",
10
+ "start:client": "vite --host",
11
11
  "start:api": "NODE_ENV=development nodemon api/index.js -w api",
12
12
  "clean": "rm -rf .blocklet",
13
13
  "bundle": "npm run bundle:client && npm run bundle:api",
14
- "bundle:client": "PUBLIC_URL='/.blocklet/proxy/<%= did %>' craco build",
14
+ "bundle:client": "vite build",
15
15
  "bundle:api": "npm run clean && blocklet bundle --zip --create-release",
16
16
  "deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
17
17
  "upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json",
@@ -62,13 +62,16 @@
62
62
  },
63
63
  "devDependencies": {
64
64
  "@arcblock/eslint-config": "^0.2.3",
65
- "@craco/craco": "^6.4.5",
65
+ "@vitejs/plugin-react": "^2.1.0",
66
66
  "eslint": "^8.25.0",
67
67
  "husky": "^8.0.1",
68
68
  "lint-staged": "^12.5.0",
69
69
  "nodemon": "^2.0.20",
70
70
  "npm-run-all": "^4.1.5",
71
71
  "prettier": "^2.7.1",
72
- "react-scripts": "5.0.1"
72
+ "vite": "^3.1.7",
73
+ "vite-plugin-blocklet": "^0.4.72",
74
+ "vite-plugin-html": "^3.2.0",
75
+ "vite-plugin-svgr": "^2.2.1"
73
76
  }
74
77
  }
@@ -1,5 +1,5 @@
1
1
  import ReactDOM from 'react-dom/client';
2
2
  import App from './app';
3
3
 
4
- const root = ReactDOM.createRoot(document.getElementById('root'));
4
+ const root = ReactDOM.createRoot(document.getElementById('app'));
5
5
  root.render(<App />);
@@ -5,7 +5,7 @@ import Gun from 'gun';
5
5
  import { Link } from 'react-router-dom';
6
6
 
7
7
  const gun = Gun({
8
- peers: [`${window.location.origin}/gun`], // Put the relay nodes that you want here
8
+ peers: [`${window.location.origin}${window?.blocklet?.prefix || ''}gun`], // Put the relay nodes that you want here
9
9
  });
10
10
 
11
11
  export default function Home() {
@@ -0,0 +1,41 @@
1
+ import { defineConfig, loadEnv } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import { createHtmlPlugin } from 'vite-plugin-html';
4
+ import { createBlockletPlugin } from 'vite-plugin-blocklet';
5
+ import svgr from 'vite-plugin-svgr';
6
+
7
+ // https://vitejs.dev/config/
8
+ export default defineConfig(async ({ mode }) => {
9
+ const envMap = loadEnv(mode, process.cwd(), '');
10
+ const apiPort = envMap.API_PORT || 3030;
11
+ const apiPrefix = `${process.env.BLOCKLET_DEV_MOUNT_POINT || ''}/api`;
12
+ const gunPrefix = '/gun'; // ws suffix only supports first level paths
13
+
14
+ return {
15
+ plugins: [
16
+ react(),
17
+ createHtmlPlugin({
18
+ minify: true,
19
+ inject: {
20
+ data: {
21
+ title: envMap.APP_TITLE,
22
+ },
23
+ },
24
+ }),
25
+ createBlockletPlugin(),
26
+ svgr(),
27
+ ],
28
+ server: {
29
+ proxy: {
30
+ [apiPrefix]: {
31
+ target: `http://127.0.0.1:${apiPort}`,
32
+ rewrite: (path) => path.replace(apiPrefix, '/api'), // rewrite path when blocklet dev
33
+ },
34
+ [gunPrefix]: {
35
+ target: `ws://127.0.0.1:${apiPort}`,
36
+ ws: true,
37
+ },
38
+ },
39
+ },
40
+ };
41
+ });
@@ -1,2 +1,2 @@
1
1
  GENERATE_SOURCEMAP=false
2
- REACT_APP_TITLE=''
2
+ APP_TITLE=''
@@ -6,7 +6,7 @@ keywords:
6
6
  - react
7
7
  group: static
8
8
  did: ''
9
- main: build
9
+ main: dist
10
10
  author:
11
11
  name: Blocklet
12
12
  email: blocklet@arcblock.io
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
7
+ <meta name="theme-color" content="#4F6AF5" />
8
+ <meta name="description" content="Web site created using create-blocklet" />
9
+ <title><%- title %></title>
10
+ </head>
11
+ <body>
12
+ <noscript> You need to enable JavaScript to run this app. </noscript>
13
+ <div id="app"></div>
14
+ <script type="module" src="/src/index.jsx"></script>
15
+ </body>
16
+ </html>
@@ -3,12 +3,13 @@
3
3
  "version": "0.1.0",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev",
6
- "eject": "react-scripts eject",
6
+ "eject": "vite eject",
7
+ "serve": "vite preview",
7
8
  "lint": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx",
8
9
  "lint:fix": "npm run lint -- --fix",
9
- "start": "craco start",
10
+ "start": "vite --host",
10
11
  "clean": "rm -rf .blocklet",
11
- "bundle": "npm run clean && PUBLIC_URL='/.blocklet/proxy/<%= did %>' craco build && blocklet bundle --zip --create-release",
12
+ "bundle": "npm run clean && vite build && blocklet bundle --zip --create-release",
12
13
  "deploy": "npm run bundle && blocklet deploy .blocklet/bundle",
13
14
  "upload": "npm run bundle && blocklet upload .blocklet/release/blocklet.json",
14
15
  "deploy:child": "npm run bundle && blocklet deploy .blocklet/bundle --app-did=<%= did %>",
@@ -43,11 +44,14 @@
43
44
  },
44
45
  "devDependencies": {
45
46
  "@arcblock/eslint-config": "^0.2.3",
46
- "@craco/craco": "^6.4.5",
47
+ "@vitejs/plugin-react": "^2.1.0",
47
48
  "eslint": "^8.25.0",
48
49
  "husky": "^8.0.1",
49
50
  "lint-staged": "^12.5.0",
50
51
  "prettier": "^2.7.1",
51
- "react-scripts": "5.0.1"
52
+ "vite": "^3.1.7",
53
+ "vite-plugin-blocklet": "^0.4.72",
54
+ "vite-plugin-html": "^3.2.0",
55
+ "vite-plugin-svgr": "^2.2.1"
52
56
  }
53
57
  }
@@ -1,5 +1,5 @@
1
1
  import ReactDOM from 'react-dom/client';
2
2
  import App from './app';
3
3
 
4
- const root = ReactDOM.createRoot(document.getElementById('root'));
4
+ const root = ReactDOM.createRoot(document.getElementById('app'));
5
5
  root.render(<App />);
@@ -0,0 +1,26 @@
1
+ import { defineConfig, loadEnv } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import { createHtmlPlugin } from 'vite-plugin-html';
4
+ import { createBlockletPlugin } from 'vite-plugin-blocklet';
5
+ import svgr from 'vite-plugin-svgr';
6
+
7
+ // https://vitejs.dev/config/
8
+ export default defineConfig(async ({ mode }) => {
9
+ const envMap = loadEnv(mode, process.cwd(), '');
10
+
11
+ return {
12
+ plugins: [
13
+ react(),
14
+ createHtmlPlugin({
15
+ minify: true,
16
+ inject: {
17
+ data: {
18
+ title: envMap.APP_TITLE,
19
+ },
20
+ },
21
+ }),
22
+ createBlockletPlugin(),
23
+ svgr(),
24
+ ],
25
+ };
26
+ });
@@ -32,7 +32,7 @@
32
32
  "npm-run-all": "^4.1.5",
33
33
  "prettier": "^2.7.1",
34
34
  "vite": "^3.1.7",
35
- "vite-plugin-blocklet": "^0.4.70",
35
+ "vite-plugin-blocklet": "^0.4.72",
36
36
  "vite-plugin-html": "^3.2.0",
37
37
  "vite-plugin-solid": "^2.3.9"
38
38
  },
@@ -26,7 +26,7 @@
26
26
  "lint-staged": "^12.5.0",
27
27
  "prettier": "^2.7.1",
28
28
  "vite": "^3.1.7",
29
- "vite-plugin-blocklet": "^0.4.70",
29
+ "vite-plugin-blocklet": "^0.4.72",
30
30
  "vite-plugin-html": "^3.2.0",
31
31
  "vite-plugin-solid": "^2.3.9"
32
32
  },
@@ -46,7 +46,7 @@
46
46
  "prettier": "^2.7.1",
47
47
  "svelte": "^3.50.1",
48
48
  "vite": "^3.1.7",
49
- "vite-plugin-blocklet": "^0.4.70",
49
+ "vite-plugin-blocklet": "^0.4.72",
50
50
  "vite-plugin-html": "^3.2.0"
51
51
  },
52
52
  "lint-staged": {
@@ -27,7 +27,7 @@
27
27
  "prettier": "^2.7.1",
28
28
  "svelte": "^3.50.1",
29
29
  "vite": "^3.1.7",
30
- "vite-plugin-blocklet": "^0.4.70",
30
+ "vite-plugin-blocklet": "^0.4.72",
31
31
  "vite-plugin-html": "^3.2.0"
32
32
  },
33
33
  "lint-staged": {
@@ -49,7 +49,7 @@
49
49
  "npm-run-all": "^4.1.5",
50
50
  "prettier": "^2.7.1",
51
51
  "vite": "^3.1.7",
52
- "vite-plugin-blocklet": "^0.4.70"
52
+ "vite-plugin-blocklet": "^0.4.72"
53
53
  },
54
54
  "lint-staged": {
55
55
  "*.{mjs,js,vue}": [
@@ -7,6 +7,7 @@ import { createBlockletPlugin } from 'vite-plugin-blocklet';
7
7
  export default defineConfig(async ({ mode }) => {
8
8
  const envMap = loadEnv(mode, process.cwd(), '');
9
9
  const apiPort = envMap.API_PORT || 3030;
10
+ const apiPrefix = `${process.env.BLOCKLET_DEV_MOUNT_POINT || ''}/api`;
10
11
 
11
12
  return {
12
13
  plugins: [
@@ -23,7 +24,10 @@ export default defineConfig(async ({ mode }) => {
23
24
  ],
24
25
  server: {
25
26
  proxy: {
26
- '/api': `http://127.0.0.1:${apiPort}`,
27
+ [apiPrefix]: {
28
+ target: `http://127.0.0.1:${apiPort}`,
29
+ rewrite: (path) => path.replace(apiPrefix, '/api'), // rewrite path when blocklet dev
30
+ },
27
31
  },
28
32
  },
29
33
  };
@@ -28,7 +28,7 @@
28
28
  "lint-staged": "^12.5.0",
29
29
  "prettier": "^2.7.1",
30
30
  "vite": "^3.1.7",
31
- "vite-plugin-blocklet": "^0.4.70",
31
+ "vite-plugin-blocklet": "^0.4.72",
32
32
  "vite-plugin-html": "^3.2.0"
33
33
  },
34
34
  "lint-staged": {
@@ -1,12 +1,11 @@
1
1
  require('dotenv-flow').config();
2
2
 
3
+ const mountPoint = process.env.BLOCKLET_DEV_MOUNT_POINT || '';
3
4
  const port = process.env.BLOCKLET_PORT || process.env.PORT || 3000;
4
5
  const apiPort = process.env.API_PORT || 3030;
5
-
6
+ const apiPrefix = `${mountPoint}/api`;
6
7
  const whenDev = process.env.NODE_ENV === 'development';
7
8
 
8
- const mountPoint = process.env.BLOCKLET_DEV_MOUNT_POINT || '';
9
-
10
9
  module.exports = {
11
10
  publicPath: whenDev ? '' : process.env.PUBLIC_PATH || '/',
12
11
  devServer: {
@@ -17,8 +16,9 @@ module.exports = {
17
16
  webSocketURL: `wss://0.0.0.0${mountPoint}/ws`,
18
17
  },
19
18
  proxy: {
20
- '/api': {
19
+ [apiPrefix]: {
21
20
  target: `http://127.0.0.1:${apiPort}`,
21
+ rewrite: (path) => path.replace(apiPrefix, '/api'), // rewrite path when blocklet dev
22
22
  },
23
23
  },
24
24
  },
package/common/_gitignore DELETED
@@ -1,28 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
-
3
- # dependencies
4
- .pnp
5
- .pnp.js
6
- .DS_Store
7
- node_modules
8
-
9
- # testing
10
- coverage
11
-
12
- # production
13
- build
14
- dist
15
- dist-ssr
16
- .blocklet
17
-
18
- # local env files
19
- *.local
20
-
21
- # Log files
22
- logs
23
- *.log
24
- npm-debug.log*
25
- yarn-debug.log*
26
- yarn-error.log*
27
- pnpm-debug.log*
28
- lerna-debug.log*
package/common/_npmrc DELETED
@@ -1,3 +0,0 @@
1
- ## force pnpm to hoist
2
- shamefully-hoist=true
3
- strict-peer-dependencies=false
@@ -1,39 +0,0 @@
1
- require('dotenv-flow').config();
2
-
3
- const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
4
-
5
- const port = process.env.BLOCKLET_PORT || process.env.PORT || 3000;
6
- const apiPort = process.env.API_PORT || 3030;
7
- const whenDev = process.env.NODE_ENV === 'development';
8
- const mountPoint = process.env.BLOCKLET_DEV_MOUNT_POINT || '';
9
-
10
- const plugins = [new NodePolyfillPlugin({ excludeAliases: ['console'] })];
11
-
12
- const webpackConfig = whenDev
13
- ? {
14
- configure: {
15
- output: {
16
- publicPath: '', // When the dev mode as component, this line required
17
- },
18
- },
19
- plugins,
20
- }
21
- : { plugins };
22
-
23
- module.exports = {
24
- webpack: {
25
- ...webpackConfig,
26
- },
27
- devServer: {
28
- port,
29
- client: {
30
- // If you want to development this blocklet without blocklet-server, you can delete next line, otherwise the hot reload will be failed.
31
- webSocketURL: `wss://0.0.0.0${mountPoint}/ws`,
32
- },
33
- proxy: {
34
- '/api': {
35
- target: `http://127.0.0.1:${apiPort}`,
36
- },
37
- },
38
- },
39
- };
@@ -1,35 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
7
- <meta name="theme-color" content="#4F6AF5" />
8
- <meta name="description" content="Web site created using create-blocklet" />
9
- <script src="__meta__.js"></script>
10
- <!--
11
- Notice the use of %PUBLIC_URL% in the tags above.
12
- It will be replaced with the URL of the `public` folder during the build.
13
- Only files inside the `public` folder can be referenced from the HTML.
14
-
15
- Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
16
- work correctly both with client-side routing and a non-root public URL.
17
- Learn how to configure a non-root public URL by running `npm run build`.
18
- -->
19
- <title>%REACT_APP_TITLE%</title>
20
- </head>
21
- <body>
22
- <noscript>You need to enable JavaScript to run this app.</noscript>
23
- <div id="root"></div>
24
- <!--
25
- This HTML file is a template.
26
- If you open it directly in the browser, you will see an empty page.
27
-
28
- You can add webfonts, meta tags, or analytics to this file.
29
- The build step will place the bundled scripts into the <body> tag.
30
-
31
- To begin the development, run `npm start` or `yarn start`.
32
- To create a production bundle, use `npm run build` or `yarn build`.
33
- -->
34
- </body>
35
- </html>
@@ -1,41 +0,0 @@
1
- require('dotenv-flow').config();
2
-
3
- const port = process.env.BLOCKLET_PORT || process.env.PORT || 3000;
4
- const apiPort = process.env.API_PORT || 3030;
5
-
6
- const whenDev = process.env.NODE_ENV === 'development';
7
-
8
- const mountPoint = process.env.BLOCKLET_DEV_MOUNT_POINT || '';
9
-
10
- module.exports = {
11
- devServer: {
12
- port,
13
- client: {
14
- // If you want to development this blocklet without blocklet-server, you can delete next line, otherwise the hot reload will be failed.
15
- webSocketURL: `wss://0.0.0.0${mountPoint}/ws`,
16
- },
17
- proxy: [
18
- {
19
- context: ['/api'],
20
- target: `http://127.0.0.1:${apiPort}`,
21
- },
22
- {
23
- context: ['/gun'],
24
- target: `ws://127.0.0.1:${apiPort}`,
25
- ws: true,
26
- },
27
- ],
28
- },
29
- webpack: {
30
- configure: {
31
- module: {
32
- noParse: /gun\.js$/,
33
- },
34
- output: whenDev
35
- ? {
36
- publicPath: '', // When the dev mode as component, this line required
37
- }
38
- : {},
39
- },
40
- },
41
- };
@@ -1,35 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
7
- <meta name="theme-color" content="#4F6AF5" />
8
- <meta name="description" content="Web site created using create-blocklet" />
9
- <script src="__meta__.js"></script>
10
- <!--
11
- Notice the use of %PUBLIC_URL% in the tags above.
12
- It will be replaced with the URL of the `public` folder during the build.
13
- Only files inside the `public` folder can be referenced from the HTML.
14
-
15
- Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
16
- work correctly both with client-side routing and a non-root public URL.
17
- Learn how to configure a non-root public URL by running `npm run build`.
18
- -->
19
- <title>%REACT_APP_TITLE%</title>
20
- </head>
21
- <body>
22
- <noscript>You need to enable JavaScript to run this app.</noscript>
23
- <div id="root"></div>
24
- <!--
25
- This HTML file is a template.
26
- If you open it directly in the browser, you will see an empty page.
27
-
28
- You can add webfonts, meta tags, or analytics to this file.
29
- The build step will place the bundled scripts into the <body> tag.
30
-
31
- To begin the development, run `npm start` or `yarn start`.
32
- To create a production bundle, use `npm run build` or `yarn build`.
33
- -->
34
- </body>
35
- </html>
@@ -1,28 +0,0 @@
1
- const port = process.env.BLOCKLET_PORT || process.env.PORT || 3000;
2
-
3
- const whenDev = process.env.NODE_ENV === 'development';
4
-
5
- const mountPoint = process.env.BLOCKLET_DEV_MOUNT_POINT || '';
6
-
7
- const webpackConfig = whenDev
8
- ? {
9
- configure: {
10
- output: {
11
- publicPath: '', // When the dev mode as component, this line required
12
- },
13
- },
14
- }
15
- : {};
16
-
17
- module.exports = {
18
- webpack: {
19
- ...webpackConfig,
20
- },
21
- devServer: {
22
- port,
23
- client: {
24
- // If you want to development this blocklet without blocklet-server, you can delete next line, otherwise the hot reload will be failed.
25
- webSocketURL: `wss://0.0.0.0${mountPoint}/ws`,
26
- },
27
- },
28
- };
@@ -1,35 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
7
- <meta name="theme-color" content="#4F6AF5" />
8
- <meta name="description" content="Web site created using create-blocklet" />
9
- <script src="__meta__.js"></script>
10
- <!--
11
- Notice the use of %PUBLIC_URL% in the tags above.
12
- It will be replaced with the URL of the `public` folder during the build.
13
- Only files inside the `public` folder can be referenced from the HTML.
14
-
15
- Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
16
- work correctly both with client-side routing and a non-root public URL.
17
- Learn how to configure a non-root public URL by running `npm run build`.
18
- -->
19
- <title>%REACT_APP_TITLE%</title>
20
- </head>
21
- <body>
22
- <noscript>You need to enable JavaScript to run this app.</noscript>
23
- <div id="root"></div>
24
- <!--
25
- This HTML file is a template.
26
- If you open it directly in the browser, you will see an empty page.
27
-
28
- You can add webfonts, meta tags, or analytics to this file.
29
- The build step will place the bundled scripts into the <body> tag.
30
-
31
- To begin the development, run `npm start` or `yarn start`.
32
- To create a production bundle, use `npm run build` or `yarn build`.
33
- -->
34
- </body>
35
- </html>