javascript - Webpack 配置不接受配置模式选项

标签 javascript node.js reactjs webpack webpack-hot-middleware

** 尝试向 webpack 配置添加模式选项时出现错误我需要配置 {mode:'developement' } 以通过查看此答案启用 hmp github.com/webpack-contrib/webpack-hot-middleware/问题/…**

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration has an unknown property 'mode'. These properties are valid: object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? } For typos: please correct them. For loader options: webpack 2 no longer allows custom properties in configuration. Loaders should be updated to allow passing options via loader options in module.rules. Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader: plugins: [ new webpack.LoaderOptionsPlugin({ // test: /.xxx$/, // may apply this only for some modules options: { mode: ... } }) ] at webpack (C:\Users\asdf\WebstormProjects\node_modules\webpack\lib\webpack.js:19:9) at Object. ( at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) at startup (internal/bootstrap/node.js:282:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

    /* eslint-disable */
const path = require('path');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const commonConfig = require('./webpack.config.common');

module.exports = webpackMerge(
  commonConfig,
  {
    devtool: 'cheap-module-eval-source-map',
    entry: {
      main: ['babel-polyfill', 'webpack-hot-middleware/client', './app/index.js'],
    },
    output: {
      path: __dirname,
      publicPath: '/',
      filename: '[hash].bundle.js',
    },
    module: {
      rules: [
        {
          test: /\.mspcss/,
          use: [
            'style-loader',
            'css-loader?modules=true&importLoaders=1&localIdentName=[local]___[hash:base64:5]',
            'resolve-url-loader',
            'sass-loader?sourceMap'
          ]
        },
        {
          test: /\.scss$/,
          use: ['style-loader', 'css-loader', 'sass-loader?sourceMap']
        },
        {
          test: /\.css$/,
          use: ['style-loader', 'css-loader']
        },
      ],
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: JSON.stringify('development'),
          BABEL_ENV: JSON.stringify('development'),
        },
        __DEV__: true,
      }),
      new webpack.HotModuleReplacementPlugin(),
      new webpack.optimize.OccurrenceOrderPlugin(),
      new webpack.NoErrorsPlugin(),
      new HtmlWebpackPlugin({
        title: 'some- Development',
        template: path.resolve(__dirname, 'index.ejs'),
        filename: path.resolve(__dirname, 'index.html'),
        favicon: 'favicon.ico',
        inject: 'body'
      }),

    ]
  }
)
/* eslint-enable */

最佳答案

您使用的是什么版本的 webpack?您可能使用的是版本 2 或 3,而最新版本的 webpack-dev-server (3.2.1) 以 webpack 4 为目标。我遇到了同样的问题,并通过安装 webpack-dev-server 版本 2.11.5 修复了它

npm uninstall webpack-dev-server
npm i -D webpack-dev-server@2.11.5

关于javascript - Webpack 配置不接受配置模式选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54694326/

相关文章:

javascript - 如何迭代对象内的数组?

javascript - 如何使盒子从侧面扩展一段距离

node.js - Clojurescript - 正确调用 native 模块的 promise

html - 将单选按钮响应解析为数组 (Express.js)

javascript - 将属性传递给 DOM 中的 React 组件

javascript - 由 Flux Store 控制的 React Form(最佳实践?)

javascript - 从状态中删除值(设置新状态)

javascript - 如何使用 setTimeout 和 Promise 使这段 JS 代码更实用?

node.js - 如何在Cloud9IDE中使用非纯JS(C++)Node.js模块?

javascript - 如何使用 React 的上下文功能将 HTML5 Canvas 上下文传递给 this.props.children?