rollup-plugin-fable

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

Rollup plugin for Fable, the F# to JavaScript compiler. Current version 2.0.0 enables bundling F# projects with Rollup by invoking the Fable compiler during the build process. Maintained as part of the Fable ecosystem, it integrates with Babel for transpilation and supports options like custom compiler directives, typed arrays, and Fable plugins. Key differentiators: seamless integration with F# tooling, supports Fable's compile-time metaprogramming, and requires careful path resolution to avoid conflicts with NuGet cache.

error Error: Cannot find module '@babel/core'
cause Missing peer dependency @babel/core.
fix
npm install --save-dev @babel/core
error Error: Plugin returned an object which has a function but not a generateBundle property
cause Incorrect usage of the plugin in rollup.config.js (e.g., calling fable() incorrectly).
fix
Ensure fable is invoked as a function in the plugins array, e.g., plugins: [fable({ babel: babelOptions })]
error Error: Cannot resolve module 'fable-utils'
cause Missing dependency fable-utils.
fix
npm install --save-dev fable-utils
error TypeError: fableUtils.resolveBabelOptions is not a function
cause Incorrect import or version of fable-utils.
fix
Ensure fable-utils is installed and imported correctly: import fableUtils from 'fable-utils'
gotcha Path resolution: Must use absolute paths for entry and node_modules to avoid conflicts with Fable pulling files from NuGet cache.
fix Use path.join(__dirname, relativePath) for all file paths.
gotcha Babel options must be resolved via fableUtils.resolveBabelOptions to share the same instance across plugins.
fix Use fableUtils.resolveBabelOptions() to create babel options object.
gotcha DefineConstants property in .fsproj is ignored; use the 'define' option instead.
fix Pass array of compiler directives via define option, e.g., fable({ define: ['DEBUG'] }).
gotcha Requires @babel/core as a peer dependency. Missing it causes runtime errors.
fix Install @babel/core: npm install --save-dev @babel/core
npm install rollup-plugin-fable
yarn add rollup-plugin-fable
pnpm add rollup-plugin-fable

Configures Rollup to bundle an F# project using Fable, with Babel for transpilation and node-resolve for module resolution.

import path from 'path';
import fableUtils from 'fable-utils';
import fable from 'rollup-plugin-fable';
import nodeResolve from 'rollup-plugin-node-resolve';

function resolve(relativePath) {
  return path.join(__dirname, relativePath);
}

var babelOptions = fableUtils.resolveBabelOptions({
  'presets': [
    ['es2015', {'modules': false}]
  ]
});

export default {
  entry: resolve('./my-app.fsproj'),
  dest: resolve('./dist/bundle.js'),
  plugins: [
    fable({ babel: babelOptions }),
    nodeResolve({
      customResolveOptions: {
        moduleDirectory: resolve('./node_modules')
      }
    })
  ],
  format: 'cjs'
};