Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: farm hmr error #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/benchmark/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ async function main() {
},
{
name: 'farm',
port: 3000,
port: 9000,
startedRegex: /Ready in/,
clean({ cwd }: { cwd: string }) {
fs.rmSync(path.join(cwd, 'dist'), { recursive: true, force: true });
fs.rmSync(path.join(cwd, 'node_modules/.farm'), { recursive: true, force: true });
},
},
{
Expand Down Expand Up @@ -95,7 +94,7 @@ async function main() {
}
sum += new Date().getTime() - pageLoadStart;

if (opts.buildTool.rootFile && !isFarm) {
if (opts.buildTool.rootFile) {
// wait for browser runtime ready
await new Promise((resolve) => setTimeout(resolve, 300));
let origin = fs.readFileSync(opts.buildTool.rootFile, 'utf-8');
Expand All @@ -107,7 +106,7 @@ async function main() {
fs.writeFileSync(opts.buildTool.rootFile, origin);
}

if (opts.buildTool.leafFile && !isFarm) {
if (opts.buildTool.leafFile) {
// wait for browser runtime ready
await new Promise((resolve) => setTimeout(resolve, 300));
let origin = fs.readFileSync(opts.buildTool.leafFile, 'utf-8');
Expand Down Expand Up @@ -179,8 +178,8 @@ async function main() {
} : {}
),
// TODO: fix farm dev server
'Root HMR time': name === 'farm' ? '' : `${rootHmr.toFixed(2)}ms`,
'Leaf HMR time': name === 'farm' ? '' : `${leafHmr.toFixed(2)}ms`,
'Root HMR time': `${rootHmr.toFixed(2)}ms`,
'Leaf HMR time': `${leafHmr.toFixed(2)}ms`,
'production time': `${production.toFixed(2)}ms`,
'js size': `${(jsSize / 1024).toFixed(2)}kB`,
}));
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bundler": "bin/cli.js"
},
"dependencies": {
"@farmfe/core": "^1.1.3",
"@farmfe/core": "1.2.6",
"@farmfe/plugin-react": "^1.1.0",
"@umijs/mako": "^0.5.2",
"@rsbuild/core": "^0.6.10",
Expand Down
39 changes: 12 additions & 27 deletions packages/bundler/src/bundlers/Farm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { BaseBundler, BaseBundlerBuildOpts, BaseBundlerOpts } from "./BaseBundler";
import { build, Server, logger, Compiler } from '@farmfe/core';
// import react from '@farmfe/plugin-react';

import { build, start } from '@farmfe/core';
interface FarmOpts extends BaseBundlerOpts {
}

Expand All @@ -13,40 +11,27 @@ export class Farm extends BaseBundler {
async build(_opts: BaseBundlerBuildOpts = {}) {
const buildOpts = {
root: this.opts.root,
compilation: {
persistentCache: false,
sourcemap: false,
},
plugins: [
// react,
'@farmfe/plugin-react'
],
};
await build(buildOpts);
}

async dev(_opts: BaseBundlerBuildOpts = {}) {

const buildOpts = {
root: this.opts.root,
output: {
publicPath: '/',
compilation: {
persistentCache: false,
},
plugins: ['@farmfe/plugin-react']
};
let compiler = new Compiler({
config: buildOpts,
jsPlugins: [
// react,
],
rustPlugins: [],
});
let server = new Server({
compiler,
logger,
});
await server.createServer({
// @ts-ignore
hmr: {
port: 3000,
host: '0.0.0.0',
},
port: 3000,
host: '0.0.0.0',
});
server.listen();

await start(buildOpts);
}
}
Loading