Fractal Webpack Plugin
raw JSON → 4.1.7 verified Sat Apr 25 auth: no javascript
A webpack plugin to integrate Fractal (a component library / styleguide tool) into a webpack build workflow. Current stable version is 4.1.7. It supports webpack 4 and 5, and Fractal 1.x. The plugin can either start a development server or build a static styleguide during webpack compilation. Key differentiators include simple configuration via a Fractal config file, seamless integration with webpack, and support for both server and build modes. Release cadence is irregular; last release was in 2023. Requires Node.js 10+.
Common errors
error TypeError: FractalWebpackPlugin is not a constructor ↓
cause Attempted to use import statement which may not resolve to the default export properly.
fix
Use const FractalWebpackPlugin = require('fractal-webpack-plugin');
error Error: Cannot find module 'fractal.config.js' ↓
cause The fractal config file is missing or the configPath option points to a non-existent file.
fix
Ensure the fractal config file exists at the specified path. Since v4.1.3, the default is 'fractal.config.js'.
error Error: Mode must be either 'server' or 'build' ↓
cause An invalid mode value was passed to the plugin options.
fix
Set mode to 'server' or 'build'.
Warnings
breaking Remove browsersync option from plugin (v3.0.0). Set it in fractal config file instead. ↓
fix Remove the 'browsersync' option from the plugin options and configure browsersync in your fractal.config.js if needed.
gotcha Default config filename changed from 'fractal.js' to 'fractal.config.js' in v4.1.3. If no configPath is specified, the plugin will look for 'fractal.config.js' first, and fall back to 'fractal.js'. ↓
fix Rename your fractal config file to 'fractal.config.js' or set the configPath option explicitly.
breaking Plugin requires webpack 4 or 5. It will not work with webpack 3 or earlier. ↓
fix Upgrade webpack to version 4 or 5.
gotcha The plugin does not provide a default export in ESM. Using import may fail in some bundlers. ↓
fix Use CommonJS require() or ensure your bundler handles CJS interop.
Install
npm install fractal-webpack-plugin yarn add fractal-webpack-plugin pnpm add fractal-webpack-plugin Imports
- FractalWebpackPlugin wrong
import FractalWebpackPlugin from 'fractal-webpack-plugin';correctconst FractalWebpackPlugin = require('fractal-webpack-plugin'); - FractalWebpackPlugin wrong
new FractalWebpackPlugin()correctnew FractalWebpackPlugin({ mode: 'server' }) - options wrong
new FractalWebpackPlugin({ mode: 'server', configPath: 'fractal.js' })correctnew FractalWebpackPlugin({ mode: 'build', configPath: './path/to/fractal.config.js' })
Quickstart
const path = require('path');
const FractalWebpackPlugin = require('fractal-webpack-plugin');
module.exports = {
entry: path.resolve('./src/index.js'),
output: {
path: path.resolve('./dist'),
filename: 'bundle.js'
},
plugins: [
new FractalWebpackPlugin({
mode: 'build',
configPath: './fractal.config.js'
})
]
};