我的文件结构如下:
Project
|
+-- src/
| |
| +-- index.js
|
+-- index.html
|
+-- webpack.config.js
的src / index.js:
document.write("Hello World.");
的index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>webpack learning</title>
<script src="builds/bundle.js"></script>
</head>
<body>
</body>
</html>
webpack.config.js:
var path = require('path');
module.exports = {
entry: './src',
output: {
path: path.join(__dirname, 'builds'),
filename: 'bundle.js',
}
};
当我在Project目录中运行webpack-dev-server时,webpack-dev-server正常启动并打印&#34; webpack:bundle现在是有效的。&#34;但是,当我启动浏览器并转到localhost:8080时,控制台会抱怨找不到bundle.js。实际上,没有名为&#34; build&#34;用bundle.js。但是,不是webpack-dev-server在内存中生成bundle.js吗?是否涉及任何配置问题?
答案 0 :(得分:1)
查看您正在运行的命令会很有帮助,但是如果我不得不猜测这个命令,我会说你可能没有设置--content-base
https://webpack.js.org/configuration/dev-server/#devserver-contentbase