kentcdodds / es6-todomvc

The vanillajs example converted to es6
https://kcd.im/webpack-workshop-repo
MIT License
351 stars 358 forks source link

Config did not export an object error thrown #27

Closed hozefaj closed 7 years ago

hozefaj commented 7 years ago

I have the below webpack.config.js, but keep getting error Config did not export an object when running command npm run webpack --env.dev

Can you point to what I am doing incorrectly? Thanks.

const webpack = require('webpack');

module.exports = env => {
    const addPlugin = (add, plugin) => add ? plugin : undefined;
    const ifProd = plugin => addPlugin(env.prod, plugin);
    const removeEmpty = array => array.filter(i => !!i);

    return {
        entry: getEntrySources(['whatwg-fetch', './src/entry.js']),
        output: {
            path: __dirname + '/.build/js',
            filename: 'bundle.js',
        },
        devtool: 'cheap-module-source-map',
        module: {
            preLoaders: [{
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loaders: [
                    'source-map',
                ],
            },
          ],
            loaders: [{
                test: /\.less$/,
                include: /src/,
                loaders: [
                    'style',
                    'css',
                    'postcss?browsers=last 3 versions',
                    'less',
                ],
            }, {
                test: /\.(jpe?g|png|gif|svg)$/i,
                loaders: [
                    'url?limit=8192',
                    'img',
                ],
            }, {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loaders: [
                    'react-hot',
                    'babel?presets[]=react,presets[]=es2015',
                    'eslint',
                ],
            }, {
                test: /\.json$/,
                include: /lib|node_modules/,
                loaders: [
                    'json',
                ],
            },
          ],
        },
        plugins: removeEmpty([
            ifProd(new webpack.optimize.UglifyJsPlugin({
                compress: {
                    warnings: false,
                    screw_ie8: true,
                },
            })),
        ]),
    };
};

function getEntrySources(sources) {
    return sources;
}
kentcdodds commented 7 years ago

You must be using version 2 of webpack (currently beta) to utilize the function API.

hozefaj commented 7 years ago

So if I am using version 2, how can I go about achieving a similar result?

kentcdodds commented 7 years ago

You shouldn't be getting that error with version 2. Make sure that's what you have, then file an issue with the Webpack project if you're still getting that error.