webpack-setup-env

Setup webpack config with additional env property

Usage no npm install needed!

<script type="module">
  import webpackSetupEnv from 'https://cdn.skypack.dev/webpack-setup-env';
</script>

README

webpack-setup-env

Travis CI node npm

Setup webpack config with additional env property like babel preset options.


Install

$ npm install webpack-setup-env

Usage

// webpack.config.js
const path = require('path');
const webpack = require('webpack');
const webpackSetup = require('webpack-setup-env');

module.exports = webpackSetup({
    output: {
        path: path.resolve(__dirname, 'dist'),
        publicPath: '/'
    },
    module: {...},
    plugins: [new webpack.DefinePlugin({...})],
    resolve: {...},
    env: {
        development: {
            mode: 'development',
            devtool: 'inline-source-map',
            entry: [
                'webpack-hot-middleware/client',
                path.resolve(__dirname, 'src/app.js')
            ],
            output: {
                filename: 'js/app.bundle.js'
            },
            plugins: [...]
        },
        production: {
            mode: 'production',
            entry: [
                path.resolve(__dirname, 'src/app.js')
            ],
            output: {
                filename: 'js/app.[hash].bundle.js'
            },
            plugins: [ ... ]
        },
        ...
    }
});

API

webpackSetup(options)

  • Params:
    • options: <object> - Webpack configuration.
      • options.env[process.env.NODE_ENV] - Webpack configuration
  • Returns: <object> - Merged by lodash.mergeWith

Inspiration

License

MIT © Guntur Poetra