Reputation: 141
I can not run webpack serve. My configs:
//webpack.config.js
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
module.exports = {
mode: 'development',
devServer: {
historyApiFallback: true,
contentBase: path.resolve(__dirname, './dist'),
open: true,
compress: true,
hot: true,
port: 8080,
allowedHosts: 'all',
},
entry: {
main: path.resolve(__dirname, './src/index.js'), // точка входа приложения
},
output: {
path: path.resolve(__dirname, './dist'), // точка выхода приложения, директория
filename: '[name].bundle.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'webpack Boilerplate',
template: path.resolve(__dirname, './src/template.html'), // шаблон
filename: 'index.html', // название выходного файла
}),
new CleanWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
],
module: {
rules: [...],
}
}
// package.json { ... "scripts": { "start": "webpack serve", "build": "webpack", "test": "echo "Error: no test specified" && exit 1" }, ... }
Error:
skif@PC:~/WebstormProjects/webpack-tutorial$ yarn start
yarn run v1.22.5
$ webpack serve
[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options has an unknown property 'contentBase'. These properties are valid:
object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, setupExitSignals?, static?, watchFiles?, webSocketServer? }
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
skif@PC:~/WebstormProjects/webpack-tutorial$
Any ideas? I don't know what happening.
Upvotes: 1
Views: 2777
Reputation: 331
You need to remove contentBase from devServer section. Error is saying that contentBase is not among possible options
Configuration for devServer is here: https://webpack.js.org/configuration/dev-server/
BTW, Webpack4 had contentBase option https://v4.webpack.js.org/configuration/dev-server/#devservercontentbase
For the Webpack5 use https://webpack.js.org/configuration/dev-server/#directory
Upvotes: 1