鉴于最新版本的webpack和webpack-dev-server of 4.6.0
和 3.1.3
,过去我似乎已经不再这样做了 .
如果我检查我的chrome检查器(Ctrl Shift I) - > Sources
选项卡并查看 Network
选项卡和 localhost:8080
,我只能看到两个条目:
-
(索引)
-
bundle.js
我应该在那里看到我想要服务的图像文件,但我没有 . 当我在控制台中看到类似这样的东西时,它真的很令人沮丧:
Content not from webpack is served from C:\Users\PC-user\WebstormProjects\untitled/assets/
但实际上,实际上并没有提供任何服务 . 感觉相当背叛 .
无论如何,这些是我的文件:
folder structure
-
资产
-
node_modules
-
src
-
package.json
-
package-lock.json
-
webpack.config.js
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: {
app: './src/index.js'
},
devServer: {
// contentBase: './dist',
contentBase: __dirname + "/assets/",
hot: true,
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
title: 'Output Management'
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
],
output: {
path: __dirname + "/assets/",
filename: 'bundle.js',
chunkFilename: '[name].js'
},
};
1 回答
也遇到了麻烦 . 但这有帮助 .
为我工作 . public是我的静态文件所在的位置 .