webpack base config as a function doesn't work

倖福魔咒の 提交于 2019-12-23 20:06:52

问题


I'm testing out dev / prod config files using the method from the docs here https://webpack.js.org/guides/production/#simple-approach

But when I switch my base config to a function I get the following error WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration should be an object.

Im using webpack 3.0.0

Original webpack.config.js

const path = require('path');
const webpack = require('webpack');

    module.exports = {
      entry: [
        'webpack/hot/dev-server',
        'webpack-hot-middleware/client',
        './src/index.js'
      ],
      output: {
        publicPath: '/',
        path: path.join(__dirname, 'build/static'),
        filename: 'jb.js'
      },
      watch: true,
      module: {
        loaders: [
          {
            test: /\.js$/,
            loaders: ['react-hot-loader', 'babel-loader'],
            exclude: /node_modules/,
            include: __dirname
          }
        ]
      },
      plugins: [
        new webpack.HotModuleReplacementPlugin({
            // exclude hot-update files
            test: /^(?!.*(hot)).*/
        })
      ]
    }

Base config as a function

const path = require('path');
const webpack = require('webpack');

module.exports = (env) => {
  return {
    entry: [
      'webpack/hot/dev-server',
      'webpack-hot-middleware/client',
      './src/index.js'
    ],
    output: {
      publicPath: '/',
      path: path.join(__dirname, 'build/static'),
      filename: 'jb.js'
    },
    watch: true,
    module: {
      loaders: [
        {
          test: /\.js$/,
          loaders: ['react-hot-loader', 'babel-loader'],
          exclude: /node_modules/,
          include: __dirname
        }
      ]
    },
    plugins: [
      new webpack.HotModuleReplacementPlugin({
        test: /^(?!.*(hot)).*/
      })
    ]
  }
}

来源:https://stackoverflow.com/questions/44738249/webpack-base-config-as-a-function-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!