@brillout/webpack-config-mod

<!---

Stats

StarsIssuesVersionUpdatedCreatedSize
@brillout/webpack-config-mod
54150.5.1310 months ago3 years agoMinified + gzip package size for @brillout/webpack-config-mod in KB

Readme

@brillout/webpack-config-mod

Webpack config modifiers.

Contents

Usage Example

// ./example.js

const mod = require('@brillout/webpack-config-mod'); // npm install @brillout/webpack-config-mod

const assert = require('reassert');
const path = require('path');

const config = {
    entry: './path/to/entry-file.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'my-first-webpack.bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: ['@babel/preset-env']
                        }
                    }
                ]
            }
        ]
    }
};

mod.setRule(config, '.css', {use: ['style-loader', 'css-loader']});
mod.addBabelPreset(config, '@babel/preset-react');
mod.addBabelPlugin(config, '@babel/plugin-proposal-decorators');

const jsRule = mod.getRule(config, '.js');
const babelLoader = jsRule.use.find(({loader}) => loader==='babel-loader');
assert(babelLoader.options.presets.includes('@babel/preset-env'));
assert(babelLoader.options.presets.find(preset => preset[0]==='@babel/preset-react'));
assert(babelLoader.options.plugins.find(preset => preset[0]==='@babel/plugin-proposal-decorators'));

const entries = mod.getEntries(config);
assert(entries['main'][0] === './path/to/entry-file.js');

console.log("Success");

API

  • setRule(config, filenameExtension, newRule)


    Add or modify the rule that matches file names ending with `filenameExtension`.
  • getRule(config, filenameExtension, {canBeMissing=false}={})


    Get the rule that matches file names ending with `filenameExtension`.
  • getEntries(config)


    Get all the entries of `config`.
  • addBabelPlugin(config, babelPlugin)


    Add a babel plugin to all `babel-loader` loaders' options object.
  • addBabelPreset(config, babelPreset)


    Add a babel preset to all `babel-loader` loaders' options object.
  • modifyBabelOptions(config, action)


    Apply the `action` function to all `babel-loader` loaders' options object.
  • addExtension(config, extension)


    Add `extension` to `config.resolve.extensions` (only if missing).

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.