0.5.13 • Published 4 years ago

@brillout/webpack-config-mod v0.5.13

Weekly downloads
4
License
-
Repository
github
Last release
4 years ago

@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).

0.5.12

4 years ago

0.5.13

4 years ago

0.5.11

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.13-next.0

6 years ago

0.1.12

6 years ago

0.1.12-next.0

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1-rc.21

6 years ago