lws-static is a dedicated middleware plugin for the lws (local-web-server) ecosystem, designed to serve static files efficiently. It internally wraps koa-static, leveraging its robust capabilities for features like caching and directory indexing. The package is currently at version 3.1.1, actively maintained with periodic updates to its underlying dependencies, notably koa-static, and to ensure compatibility with the lws core framework. Its primary differentiator is seamless integration with lws's configuration system, allowing static file serving to be configured via concise CLI arguments or a programmatic lws setup. This approach simplifies the creation of development servers by offering a unified interface for defining the static root directory, cache control (max-age), request deferral, custom index files, and additional filename extensions, abstracting away direct koa-static configuration for lws users.
npm install lws-staticVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic setup of `lws` with `lws-static` to serve static files from a temporary directory. It configures caching, an index file, and proper cleanup.
Migrate your project to use ES modules (`import` statements) or pin `lws-static` to a version prior to 3.0.0 if CommonJS is strictly required for your project.
Ensure your Node.js environment is updated to at least v14 and upgrade your `local-web-server` package to version 6.x or newer to ensure compatibility.
Consult the `lws-static` README or `lws --help` for the correct option syntax when using the CLI, and ensure programmatic options are passed as an object to the `createStaticMiddleware()` function.
Refer to the official `koa-static` documentation for detailed information on static file serving mechanisms and advanced configuration options.
Update your import statement from `const middleware = require('lws-static');` to `import middleware from 'lws-static';` and ensure your project is configured for ES modules (e.g., using `"type": "module"` in `package.json` or `.mjs` file extensions).Ensure you are using `import createStaticMiddleware from 'lws-static';` and that you are calling `createStaticMiddleware()` as a function when adding it to your `lws` stack, e.g., `stack: [createStaticMiddleware({ directory: './public' })]`.Double-check the `directory` path for typos or incorrect relative paths. Ensure the directory exists and that your application has the necessary read permissions. Consider using absolute paths with `path.join(__dirname, 'your-static-folder')` for robustness.