Dev utils as devDependencies
Production dependencies and dev dependencies should be installed as such so that production builds do not contain development dependencies. That being said, it can be difficult to dynamically require/import dependencies based on whether they have been installed or not.
Consider a Fela configuration relying on
fela-plugin-embeddedfela-beautifierfela-plugin-validatordevDependenciesWith webpack
The main idea is to have 2 different files exporting plugins and enhancers (or any piece Fela configuration that differs between environments, really): one for development (
fela.development.jsfela.production.jsThe development one could look like this:
fela.development.js
import beautifier from 'fela-beautifier'import validator from 'fela-plugin-validator'import embedded from 'fela-plugin-embedded'export const enhancers = [beautifier()]export const plugins = [validator(), embedded()]And the production one:
fela.production.js
import embedded from 'fela-plugin-embedded'export const enhancers = []export const plugins = [embedded()]Then in Webpack, we provide the content of the correct file as a global variable (e.g.
FELA_CONFIGwebpack.config.js
const { resolve } = require('path')const { ProvidePlugin } = require('webpack')const NODE_ENV = process.env.NODE_ENVmodule.exports = {  plugins: [    new ProvidePlugin({ FELA_CONFIG: resolve(`src/fela.${NODE_ENV}.js`) }),  ],}Finally, when instantiating the Fela renderer, read the plugins and enhancers from the global
FELA_CONFIG/* global FELA_CONFIG */export default createRenderer({  plugins: FELA_CONFIG.plugins,  enhancers: FELA_CONFIG.enhancers,})This recipe relies on Webpack, but it should be applicable with any bundler able to expose a global variable.