3

我正在使用https://webpack.js.org/guides/production/#simple-approach文档中的方法测试 dev / prod 配置文件

但是当我将我的基本配置切换到一个函数时,我收到以下错误WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration should be an object.

我在用着webpack 3.0.0

原来的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)).*/
        })
      ]
    }

基本配置作为函数

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)).*/
      })
    ]
  }
}
4

0 回答 0