Skip to content

Commit

Permalink
refactor: websocket and devserver (#700)
Browse files Browse the repository at this point in the history
* feat: websocket class

* chore: update code

* chore: update grade demo

* chore: update test server

* chore: init ws server migrate devserver

* chore: update test websocket success

* chore: update code

* chore: optimize server with ws code

* chore: optimize server with ws code

* chore: remove unless code

* chore: update code

* chore: update code

* chore: update code

* chore: update code

* chore: update lock
  • Loading branch information
ErKeLost authored Nov 6, 2023
1 parent a973690 commit 032a05d
Show file tree
Hide file tree
Showing 18 changed files with 2,787 additions and 3,001 deletions.
20 changes: 10 additions & 10 deletions examples/qrcode/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="canvas"></div>
<script src="./index"></script>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="canvas"></div>
<script src="./index"></script>
</body>
</html>
10 changes: 5 additions & 5 deletions examples/qrcode/index.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import QRCode from 'qrcode'
import QRCode from 'qrcode';

// With promises
QRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, function (err, canvas) {
if (err) throw err
if (err) throw err;

var container = document.getElementById('canvas')
container.appendChild(canvas)
})
var container = document.getElementById('canvas');
container.appendChild(canvas);
});
18 changes: 9 additions & 9 deletions examples/react-antd/farm.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserConfig } from '@farmfe/core';
import type { UserConfig } from "@farmfe/core";

function defineConfig(config: UserConfig) {
return config;
Expand All @@ -7,23 +7,23 @@ function defineConfig(config: UserConfig) {
export default defineConfig({
compilation: {
input: {
index: './index.html'
index: "./index.html",
},
output: {
path: './build',
publicPath: '/admin/'
path: "./build",
publicPath: "/admin/",
},
sourcemap: true
sourcemap: true,
},
server: {
// headers: {
// 'Access-Control-Allow-Origin': '*'
// },
port: 5580,
hmr: true,
writeToDisk: false,
cors: true,
host: '127.0.0.1'
hmr: {
port: 6542
}
},
plugins: ['@farmfe/plugin-react', '@farmfe/plugin-sass']
plugins: ["@farmfe/plugin-react", "@farmfe/plugin-sass"],
});
2 changes: 1 addition & 1 deletion examples/react-antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@farmfe/cli": "workspace:*",
"@farmfe/core": "workspace:*",
"@farmfe/js-plugin-sass": "workspace:*",
"@farmfe/plugin-react": "workspace:^0.3.3",
"@farmfe/plugin-react": "workspace:^0.3.4",
"@farmfe/plugin-sass": "workspace:^0.2.9",
"@types/react": "18",
"@types/react-dom": "18",
Expand Down
45 changes: 22 additions & 23 deletions examples/react/farm.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserConfig } from '@farmfe/core';
import type { UserConfig } from "@farmfe/core";

function defineConfig(config: UserConfig) {
return config;
Expand All @@ -7,16 +7,16 @@ function defineConfig(config: UserConfig) {
export default defineConfig({
compilation: {
input: {
index: './index.html'
index: "./index.html",
},
resolve: {
symlinks: true
symlinks: true,
},
define: {
BTN: 'Click me'
BTN: "Click me",
},
output: {
path: './build',
path: "./build",
publicPath: "public",
},
// sourcemap: true,
Expand All @@ -25,31 +25,30 @@ export default defineConfig({
// indentName: 'farm-[name]-[hash]'
// },
prefixer: {
targets: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 11']
}
targets: ["last 2 versions", "Firefox ESR", "> 1%", "ie >= 11"],
},
},
treeShaking: true
treeShaking: true,
},
server: {
cors: true,
port: 8260
},
plugins: [
'@farmfe/plugin-react',
'@farmfe/plugin-sass',
"@farmfe/plugin-react",
"@farmfe/plugin-sass",
{
name: 'plugin-finish-hook-test',
name: "plugin-finish-hook-test",
finish: {
executor(param, context, hookContext) {
// console.log('plugin-finish-hook-test', param, context, hookContext);
}
}
},
},
},
{
name: 'plugin-hook-context-test',
name: "plugin-hook-context-test",
load: {
filters: {
resolvedPaths: ['.+main.tsx']
resolvedPaths: [".+main.tsx"],
},
executor(param, context, hookContext) {
// console.log('plugin-hook-context-test', param, context, hookContext);
Expand All @@ -66,18 +65,18 @@ export default defineConfig({
// context.warn('test');
// context.error('test');
return null;
}
}
},
},
},
{
name: 'plugin-update-modules-hook-test',
name: "plugin-update-modules-hook-test",
updateModules: {
executor(param, context, hookContext) {
// console.log("params", param);
// console.log("context", context);
// console.log("hookContext", hookContext);
}
}
}
]
},
},
},
],
});
1 change: 1 addition & 0 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"scripts": {
"start": "farm start",
"dev": "farm start",
"build": "farm build",
"preview": "farm preview"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/server/hmr-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DevServer } from './index.js';
import { Logger, bold, cyan, green } from '../utils/index.js';
import { JsUpdateResult } from '../../binding/binding.js';
import type { Resource } from '@farmfe/runtime/src/resource-loader.js';
import { WebSocketClient } from './ws.js';

export class HmrEngine {
private _updateQueue: string[] = [];
Expand Down Expand Up @@ -70,6 +71,7 @@ export class HmrEngine {
green(`${Date.now() - start}ms`)
)}`
);

// TODO: write resources to disk when hmr finished in incremental mode
// if (this._devServer.config?.writeToDisk) {
// this._compiler.onUpdateFinish(() => {
Expand Down Expand Up @@ -120,8 +122,7 @@ export class HmrEngine {
// result: resultStr,
// count: this._devServer.ws.clients.size
// });

this._devServer.ws.clients.forEach((client) => {
this._devServer.ws.clients.forEach((client: WebSocketClient) => {
client.send(resultStr);
});

Expand Down
Loading

0 comments on commit 032a05d

Please sign in to comment.