rollup-plugin-variables

raw JSON →
0.1.1 verified Mon Apr 27 auth: no javascript maintenance

A Rollup plugin that replaces custom markers (e.g., [[VARIABLE]]) in source files with values from a separate variables file (JS, JSON, or TXT). Stable version 0.1.1. Low activity; last release in 2019. Key differentiator: allows externalizing environment-specific values without a full-fledged env replacement plugin. Limited to rollup.

error Error: Cannot find module './env.js'
cause Variables file path is resolved relative to rollup.config.js; file missing or incorrect.
fix
Ensure env.js exists in the same directory as rollup.config.js or provide absolute path via fileName option.
error TypeError: variables is not a function
cause Using named import { variables } instead of default import.
fix
Use default import: import variables from 'rollup-plugin-variables'.
error The marker format 'invalid' is not supported.
cause Marker option string or function must return a valid format like '[[]]' or '{{}}'.
fix
Use supported marker format: '[[]]', '{{}}', or another string with matching brackets.
gotcha Default marker is [[]]; double brackets required.
fix Ensure source files use [[VARIABLE_NAME]] syntax, or configure marker option.
gotcha Variables file must export an object (module.exports = ...) when format is 'js'.
fix Use module.exports = { KEY: 'value' } in .js file; for .json use JSON object directly.
deprecated Plugin is in maintenance mode; no updates expected.
fix Consider migrating to @rollup/plugin-replace or similar.
gotcha Nested markers (e.g., [[[VAR]]]) not supported; will cause undefined replacement.
fix Use flat variable names without nested brackets.
npm install rollup-plugin-variables
yarn add rollup-plugin-variables
pnpm add rollup-plugin-variables

Configures Rollup to replace [[variables]] with values from env.js during build.

// rollup.config.js
import variables from 'rollup-plugin-variables';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife'
  },
  plugins: [
    variables({
      fileName: 'env.js',
      format: 'js',
      marker: '[[]]'
    })
  ]
};