Description
I have react project based on Wepack and now want to migrate to esbuild entirely.
But when I ran it on a dev server, esbuild report " TypeError: esbuild.serve is not a function"
below is the config , pls tell me what's wrong with it? Thx!
`const esbuild = require("esbuild");
const lessPlugin = require("esbuild-plugin-less").lessPlugin;
const cssModulesPlugin = require("esbuild-plugin-css-modules").cssModulesPlugin;
const alias = require("esbuild-plugin-alias");
const path = require("path");
const port = 7002;
(async () => {
const {babel} = await import("esbuild-plugin-babel");
const { htmlPlugin } = await import("@chialab/esbuild-plugin-html");
const config = {
entryPoints: ["./public/index.html"],
bundle: true,
outdir: "./public",
define: {
"process.env.NODE_ENV": '"development"',
},
minify: false,
splitting: true,
loader: {
".js": "jsx",
".css": "css",
".less": "less",
".png": "file",
".jpg": "file",
".jpeg": "file",
".gif": "file",
".svg": "file",
},
plugins: [
babel,
cssModulesPlugin,
lessPlugin,
htmlPlugin,
alias({
"@": path.resolve(__dirname, "./src"),
}),
],
};
esbuild
.serve(
{
servedir: "public",
port,
},
config
)
.then(() => {
console.log(Development server is running on http://localhost:${port}
);
})
.catch(() => process.exit(1));
})();`