我只是无法启动此服务器,我阅读了webpack-dev-server 文档。
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
port: 9000
}
示例代码看起来很简单,但我就是无法成功启动此服务器,无论我尝试什么,不同的文件夹,它都无法获取内容!!!我是不是遗漏了什么?
任何帮助将不胜感激。
输出:
Project is running at http://0.0.0.0:8080/
webpack output is served from /assets/
Content not from webpack is served from ~/WebstormProjects/react_back/assets/
我的项目结构:
├── [drwxr-xr-x ] src
│ └── [-rw-r--r-- ] index.js
├── [drwxr-xr-x ] public
│ ├── [-rw-r--r-- ] index.html
│ ├── [drwxr-xr-x ] assets
│ │ └── [-rw-r--r-- ] bundle.js
│ └── [-rw-r--r-- ] favicon.ico
├── [-rw-r--r-- ] package.json
├── [-rw-r--r-- ] npm-debug.log
├── [-rw-r--r-- ] webpack.config.js
包.json
"scripts": {
"build": "webpack",
"dev": "webpack-dev-server --devtool eval"
},
webpack.config.js
module.exports = {
entry: __dirname + "/src/index.js",
output: {
path: __dirname + "/public",
publicPath: "/assets/",
filename: "assets/bundle.js",
chunkFilename: '[name].js'
},
devServer: {
contentBase: __dirname + "/assets/",
inline: true,
host: '0.0.0.0',
port: 8080,
},
module: {
loaders: [
{
test: /\.(jpg|jpeg|gif|png|ico)$/,
exclude: /node_modules/,
loader: 'file-loader?name=[name].[ext]'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ["es2016", "react", "env", "stage-2"]
}
}
]
}
};
版本:
➜ node -v
v7.6.0
➜ webpack-dev-server -v
webpack-dev-server 2.4.1
webpack 2.2.1