Falldot / esbuild-dev-server

This plugin allows you to start a local server with hot reloading with Esbuild

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All requests resolve to index.html

gbenson-ff opened this issue · comments

I've got this plugin set up and running a dev server, however all network requests resolve to the index.html file. This includes requests for my index.js file, which of course fails.

Would you be able to help me figure this out? I can provide more info if you tell me what you need.

As far as I can tell, any file in the root of your "dist" folder will be treated as a route, and not work as expected. (at least for JS files)
You will need to build your js into "dist/js" or something, then update index.html to request /js/xxxx.js

commented

Setting very specific staticDir seems to work, I serve index.html with relative css stylesheets from node_modules, with staticDir: "dist" somewhy there are correcty imported as css, same issue was with every other .js, as it was replaced with index.html. Also, i still encounter failed font imports, they have the same paths from node_modules as css, while second is delivered just fine...

esbuild.config.js:

esBuildDevServer.start(
	build({
		entryPoints: ["src/index.ts", "dist/index.html"],
		outdir: "dist/final",
		incremental: true,
        loader: {
            ".html": "text",
            ".ts": "ts",
        },
        bundle: true,
	}),
	{
		port:      "8080",
		watchDir:  "src",
		index:     "dist/index.html",
		staticDir: "dist",
	}
)

index.html has this scripts apart from ../node_modules/...:

<script type="text/javascript" src="/final/dist/index.js"></script>
<script type="text/javascript" src="/final/src/index.js"></script>

Directory tree:
image