package
On-demand runtime webpack compilations over HTTP
npm install webpack-http-serverGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
On-demand runtime webpack compilations over HTTP.
This package is, effectively, an Express server that exposes webpack compilations over HTTP. This means you can request to compile a module on runtime by dispatching a request like this:
POST http://127.0.0.1:8080/compilation
Content-Type: application/json
{"entry":"/Users/you/some/module.js"}The server will respond you with the compilation info:
{
"id": "COMPILATION_ID",
"previewUrl": "http://127.0.0.1/compilation/"
}Each compilation request creates a unique compilation ID and /compilations/:id route to preview the runtime of the given module after it's compiled.
I've build this library because I'm a fan of example-driven testing. When I employ it on bigger projects, it means that every test I have has a runtime usage example alongside it. While I could compile those examples before tests, I chose to have a runtime compilation server instead. Here are my reasons:
npm run build:examples before running tests, which will yield irrelevant test results.webpack-dev-server?Webpack Dev Server is a great tool to run your compilation over HTTP. However, it's scoped to a single compilation. You cannot change the entrypoint for your dev server without having to stop it, modify the webpack config, and re-run the server. This is extremely time consuming and unreliable.
npm install webpack-http-serverimport { WebpackHttpServer } from 'webpack-http-server'
const server = new WebpackHttpServer()
await server.listen()
console.log('Compilation server listening at "%s"', server.serverUrl)The compilation server runs on a random vacant port. Rely on the
serverUrlproperty to get its full address.
There are two ways to request a compilation: HTTP request and Node.js API.
fetch(`${server.serverUrl}/compilation`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
entry: '/Users/octocat/projects/demo/index.js',
}),
})const result = await server.compile(['/Users/octocat/projects/demo/index.js'])
console.log('preview is running on "%s"', result.previewUrl)Estimated unpacked size across 64 packages.
19.5 MB+
Includes dependencies.
7 direct · 3 outdated
^3.4.7
4.80.1
^4.18.1
5.3.0
^5.74.0
5.112.2
^4.2.0
4.2.0
^1.3.0
1.4.3
^4.17.13
5.0.6
^4.2.1
4.2.6