@brikcss/rollup-config-generator v0.0.16
Rollup Config Generator
About
ā ļø IMPORTANT: Brikcss follows semantic versioning. This package is currently at major version zero, which means "anything may change at any time", and it "should not be considered stable".
Rollup config generator makes it easy to generate complex configurations for RollupJS.
Contributing š
We ā¤ļøā¤ļøā¤ļø contributions of any kind, whether it's bug reports, questions or feature requests, pull requests, and especially spreading some love about this project to your friends and co-workers!
Read our contributing guidelines and get involved to support this project.
Environment support
Node | CLI | Browser | UMD | ES Module |
---|---|---|---|---|
ā | ā | ā | ā | ā |
Install š¦
npm install -D @brikcss/rollup-config-generator
Quick Start š
Get up and running in less than five minutes:
Create a new generator in your rollup config file:
Create new generator with all defaults:
import configGen from "@brikcss/rollup-config-generator";
Or Create a custom generator:
import { ConfigGen } from "@brikcss/rollup-config-generator"; const configGen = new ConfigGen({ base, sets, options, on });
Create the configuration and export it from your rollup config:
export default configGen.create(userConfig, globals);
API š¤
Note: ConfigGen contains many methods which are not documented here. Check out the source code to see what else is available.
Generate configs
const rollupConfigs = ConfigGen.create(userConfigs, globals);
userConfigs
{object[]} (required) Array of user config objects. Each config object can contain any of Rollup's configuration options, as well as the following:id
{string} If ConfigGen cannot find a filepath from package.json that can be used, theid
is used to help generate theoutput.file
(if not already set).type
{string} If this is set, ConfigGen will create a "set" of rollup configs by looking upConfigGen.sets[type]
and merging with the base and default config settings. By default,type
can bebrowser
,dependency
, ornode
, though custom sets can be created. See creating a custom generator.target
{string} If target is set, Babel will be set up to compile the bundle for the specified environment. Possible values are:modern
(modern browsers),legacy
(legacy browsers), or a number (e.g.,9
) which determines the minimum node version to target.
globals
{object} When a rollup config is compiled, if a property in globals matches${output.format}
or${output.format}:${config.modern}
, that object is merged with the rest of the rollup config. For example:globals.esm
will be merged with all rollup configs whereoutput.format
isesm
. Likewise,globals['esm:modern']
will merge with all rollup configs whereoutput.format
isesm
AND whereconfig.target
ismodern
.
Create a custom generator
const configGen = new ConfigGen({ base, sets, options, on });
base
{object} Base configuration. This gets merged with every rollup config that gets created. See source code for default values.sets
{object} Configuration sets. This allows you to create multiple rollup configs with a single user config object. In a user config object, if thetype
property exists, configs will be generated for each object in a set. The default sets are:browser
: Creates a source ESM build, as well as separate ESM and UMD builds which target both modern and legacy browsers. This should be used for modules that are intended for use in the browser.dependency
: Browser dependency builds. Since browsers do not resolve node module imports, this prebundles browser dependencies as ESM (modern only) and UMD (modern and legacy) builds. This can be used for any production dependencies you wish to provide prebundled.node
: Node builds. This generates builds intended for use in a CommonJS/Node environment.
options
{object} Configuration options:options.outputDir
{string} dist Output directory.options.pkgMap
{object} For each user config, ConfigGen checks${output.format}
and${output.format}:${config.type}
in package.json. If the field exists, that filepath is used for output.file.
on
{object} Map of the following hooks/callbacks:prependPlugins
{function}(config) => newPlugins
Prepends plugins toconfig.plugins
.insertPlugins
{function}(config) => newPlugins
Inserts plugins toconfig.plugins
.appendPlugins
{function}(config) => newPlugins
Appends plugins toconfig.plugins
.output
{function}(output, config) => output
Modifiesconfig.output
.