express-resource-compiler

raw JSON →
0.2.8 verified Fri May 01 auth: no javascript maintenance

Resource compiler and cacher for Express. Current stable version: 0.2.8. This package allows you to compile and cache resources (e.g., CSS, JavaScript templates) in an Express application. It is designed to be generic and integrate with Express's middleware pattern. The package has seen no recent updates and is in early stages, with limited documentation and community adoption. Differentiators include its focus on resource compilation and caching for Express, as opposed to more general-purpose build tools or asset pipelines. It supports a plugin-like system for custom compilers.

error Cannot find module 'resource-compiler'
cause Package not installed or not in node_modules.
fix
Run npm install resource-compiler and ensure it's in dependencies.
error compiler.middleware is not a function
cause Using import incorrectly or object is not a ResourceCompiler instance.
fix
Ensure you instantiate with new ResourceCompiler(options) and call middleware() method.
error TypeError: Cannot read property 'prototype' of undefined (in ResourceCompiler)
cause Likely using `require` with a named export instead of default.
fix
Use const ResourceCompiler = require('resource-compiler'); (no .default).
gotcha Constructor requires `compilers` object; missing it causes silent failure.
fix Always provide a `compilers` configuration with at least one extension handler.
gotcha Cache directory is created synchronously on instantiation; ensure write permissions.
fix Set `cacheDir` to a writable path or disable caching (`cache: false`).
deprecated Version 0.2.x is outdated; no updates since 2018.
fix Consider migrating to a more maintained alternative like webpack or gulp.
npm install resource-compiler
yarn add resource-compiler
pnpm add resource-compiler

Basic setup of express-resource-compiler with custom compiler for .jst files and caching enabled.

const express = require('express');
const ResourceCompiler = require('resource-compiler');

const app = express();
const compiler = new ResourceCompiler({
  cache: true,
  cacheDir: './cache',
  compilers: {
    '.jst': (content, filename) => `module.exports = ${JSON.stringify(content)};`
  }
});

app.use(compiler.middleware());

app.get('/', (req, res) => {
  res.send('Resource compiler active');
});

app.listen(3000);