f2e-server
raw JSON →f2e-server 2 (v2.20.13) is a front-end development server with built-in support for Less compilation, Babel transpilation, live reload, and middleware-based plugin architecture. It provides CLI commands for starting a dev server (`f2e start`), building to output (`f2e build`), and generating config files (`f2e conf`). Unlike heavyweight dev servers like webpack-dev-server, f2e-server focuses on simplicity and runtime-build with proxy capabilities. It ships with TypeScript type definitions but is primarily configured via CommonJS config files. The project has been updated infrequently (last release likely 2021-2022) and may lack modern features like HMR or ESM native support. The server auto-detects ports starting from 2850 and supports HTTPS and custom hostnames. It is suitable for lightweight front-end projects that need a quick development environment with minimal configuration.
Common errors
error Error: listen EADDRINUSE :::2850 ↓
error Cannot find module 'marked' ↓
error TypeError: store._set is not a function ↓
error f2e: command not found ↓
Warnings
breaking f2e-server v2.x configuration is not compatible with v1.x. Middleware signature changed from (req, resp) to (conf). ↓
deprecated The 'request' package used in examples is deprecated and will not receive security updates. ↓
gotcha If you omit 'return false' from onRoute, the request will continue to other middlewares and may cause double response. ↓
gotcha The 'no_host' option is set to false by default. If you set a host in the config, requests that don't match the host header will be ignored. ↓
Install
npm install f2e-server yarn add f2e-server pnpm add f2e-server Imports
- f2e server (CLI) wrong
npm startcorrectnpx f2e start - Default config export wrong
export default { ... }correctmodule.exports = { ... } - Middleware function wrong
function middleware(conf) { } // missing return objectcorrect(conf) => { return { onRoute, onSet, ... }; } - babel _rules wrong
useBabel: { _rules: [ { only: ['file.js'] } ] } // missing getModuleIdcorrectuseBabel: { _rules: [ { only: ['file.js'], getModuleId: ... } ] }
Quickstart
// .f2econfig.js
const path = require('path');
module.exports = {
livereload: true,
useLess: { compress: false },
useBabel: { getModuleId: p => p.replace(/\\+/g, '/') },
gzip: true,
range_size: 1024 * 1024,
middlewares: [
(conf) => {
return {
onRoute(pathname, req, resp, memory) {
if (pathname.match(/^es6/)) {
const request = require('request');
request(pathname.replace('es6', 'http://es6.ruanyifeng.com')).pipe(resp);
return false;
}
},
onSet(pathname, data, store) {
if (pathname.match(/\.md$/)) {
const res = require('marked')(data.toString());
store._set(pathname.replace(/\.md$/, '.html'), res);
}
},
buildWatcher(eventType, pathname, build) {
console.log(new Date().toLocaleString(), eventType, pathname);
}
};
}
]
}