使用'--hot'运行webpack-dev-server并发生错误,因为“configuration.entry应该是以下之一:”

时间:2018-05-23 01:26:33

标签: webpack webpack-dev-server

我的基本信息如下: *操作系统:macos *节点版本:8.7.0 * NPM版本:6.0.1 * webpack版本:4.8.3 * webpack-dev-server版本:3.1.4

当我在package.json>中添加'--hot'时脚本>喜欢这样:

function foo(){
 var a = 'test';
 bar();
}

function bar(){
 alert(a);
}

foo();

像这样的webpack.config.js:

{
     "main": "webpack.config.js",
     "dependencies": {"babel-preset-react": "^6.24.1"},
     "devDependencies": {
          "babel-loader": "^7.1.4",
          "css-loader": "^0.28.11",
          "less-loader": "^4.1.0",
          "react": "^16.3.2",
          "react-dom": "^16.3.2",
          "style-loader": "^0.21.0",
          "url-loader": "^1.0.1",
          "webpack": "^4.8.3",
          "webpack-cli": "^2.1.3",
          "webpack-dev-server": "^3.1.4"
     },
     "scripts": {
          "build": "webpack --mode production",
          "dev": "webpack-dev-server --devtool eval --progress --colors --hot --content-base build"
     }
}

当我运行:module.exports = { entry: [ 'webpack/hot/dev-server', 'webpack-dev-server/client?http://localhost:8080', path.resolve(__dirname, './app/main.js') ], output: { path: path.resolve(__dirname, './build'), filename: 'bundle.js' }, resolve: { extensions: ['.js', '.jsx'] }, module: { rules: [{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['react'] } }, { test: /\.css$/, exclude: /node_modules/, loader: 'style!css' }, { test: /\.less$/, exclude: /node_modules/, loader: 'style!css!less' },{ test: /\.(png|jpg)$/, exclude: /node_modules/, loader: 'url?limit=25000' }] } }; 然后出现错误:

npm run dev

当我删除'--hot'并且错误消失,但是当我在浏览器中运行✖ 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.entry should be one of these: object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function -> The entry point(s) of the compilation. Details: * configuration.entry should be an object. -> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array. * configuration.entry should be a string. -> An entry point without name. The string is resolved to a module which is loaded upon startup. * configuration.entry should not contain the item 'webpack/hot/dev-server' twice. * configuration.entry should be an instance of function -> A Function returning an entry object, an entry string, an entry array or a promise to these things. 时:

localhost:8080

我想念任何包裹吗?

0 个答案:

没有答案