metalsmith-rollup

raw JSON →
2.0.0 verified Mon Apr 27 auth: no javascript

A Metalsmith plugin that bundles JavaScript files using Rollup. Version 2.0.0 is current; it supports source maps and can ignore processed source files. This plugin is designed for Metalsmith build pipelines where you need to bundle ES modules with Rollup. It only supports the JavaScript API; CLI usage with metalsmith.json is not yet available. The main differentiator is its tight integration with Metalsmith's build process, allowing seamless inclusion of bundled output inside the build directory.

error TypeError: rollup is not a function
cause Using destructured import when package exports a single function
fix
Use const rollup = require('metalsmith-rollup'); not const { rollup } = require('metalsmith-rollup');
error Error: ENOENT: no such file or directory, open '...'
cause Input file path is incorrect relative to Metalsmith source directory
fix
Make sure the input path starts from your Metalsmith source directory (e.g., 'src/js/main.js' if your Metalsmith source is 'src').
gotcha input path is relative to Metalsmith source directory; output.dest is relative to Metalsmith build directory
fix Ensure input file exists inside your Metalsmith source folder, and output.dest will be placed in the build folder.
gotcha CLI usage via metalsmith.json is not yet supported; only JavaScript API works
fix Use JavaScript build file with require('metalsmith-rollup') instead of relying on metalsmith.json plugins configuration.
deprecated plugin options object (second argument) structure may change in future versions
fix Refer to documentation for current options; avoid relying on undocumented properties.
npm install metalsmith-rollup
yarn add metalsmith-rollup
pnpm add metalsmith-rollup

Shows how to use the plugin with Metalsmith to bundle a JavaScript entry point into a single output file.

const Metalsmith = require('metalsmith');
const rollup = require('metalsmith-rollup');

Metalsmith(__dirname)
  .use(rollup({
    input: 'src/js/main.js',
    output: {
      dest: 'js/bundle.js'
    }
  }))
  .build((err) => {
    if (err) throw err;
    console.log('Build complete');
  });