webpack-dev-server配置错误,但webpack工作正常

时间:2017-10-10 14:52:41

标签: webpack webpack-dev-server

当我运行webpack时,所有内容都会编译和捆绑,但是当我运行webpack-dev-server时,我收到此错误:

Invalid configuration object. webpack-dev-server has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'error'. These properties are valid:
   object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, watchOptions?, headers?, clientLogLevel?, overlay?, progress?, key?, cert?, ca?, pfx?, pfxPassphrase?, requestCert?, inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, compress?, proxy?, historyApiFallback?, staticOptions?, setup?, before?, after?, stats?, reporter?, noInfo?, quiet?, serverSideRender?, index?, log?, warn? }

我的webpack.config.js配置,如下所示:

const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')

module.exports = {
    entry: {
        bundle: path.resolve(__dirname, 'src/index.jsx'),
    },
    output: {
        publicPath: '/',
        path: __dirname + '/dist',
        filename: '[name].[chunkhash].js',
    },
    devtool: 'source-map',
    resolve: {
        extensions: ['.js', '.jsx'],
    },
    externals: {
        'react': 'React',
        'react-dom': 'ReactDOM',
    },
    devServer: {
        host: '0.0.0.0',
        port: 8088,
        historyApiFallback: true,
    },
    watchOptions: {
        aggregateTimeout: 1,
        ignored: /node_modules/,
    },
    module: {
        loaders: [{
            test: /.jsx?$/,
            loader: 'babel-loader',
            exclude: /node_modules/,
            query: {
                presets: ['es2015', 'react', 'stage-0'],
                plugins: ['transform-runtime'],
            },
        }, {
            test: /\.html$/,
            loader: 'html-loader',
        }, {
            test: /\.less$/,
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: 'css-loader!postcss-loader!less-loader',
            }),
        }, {
            test: /\.(png|svg|jpg|ico)$/,
            loader: 'file-loader?name=./img/[hash].[ext]',
        }, {
            test: /\.(ttf|woff|woff2|otf|eot)$/,
            loader: 'file-loader?name=./fonts/[hash].[ext]',
        }],
    },
    plugins: [
        new CleanWebpackPlugin(['dist'], {
            root: path.resolve(__dirname),
            verbrose: true,
        }),
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, 'src/index.html'),
        }),
        new ExtractTextPlugin({
            filename: '[name].[chunkhash].css',
            allChunks: false,
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'commons',
        }),
    ],
}

配置中没有'error'属性,webpack工作正常,只是webpack-dev-server失败了......

错过了什么?感谢您的任何建议。

1 个答案:

答案 0 :(得分:1)

webpack-dev-server repo问题解决了问题。这是一个链接:https://github.com/webpack/webpack-dev-server/issues/1142