【发布时间】:2018-09-03 11:58:17
【问题描述】:
我是 reactjs 的新手。我尝试配置对包括 index.js(包含 console.log())在内的基本索引页面的反应,但是当我尝试运行服务器时 index.html 正确显示但 bundle.js 没有加载。我搜索了很多,但没有得到正确的答案,请任何人帮助我。
我的 webpack.config.js 是
// Webpack config js.
var webpack = require("webpack");
var path = require("path");
var DIST_VAR = path.resolve(__dirname, "dist");
var SRC_VAR = path.resolve(__dirname, "src");
var config = {
entry : SRC_VAR + "\\app\\index.js",
output: {
path: DIST_VAR + "\\app\\",
filename: "bundle.js",
publicPath : "\\app\\",
},
module: {
rules: [
{
test: /\.js?/,
include: SRC_VAR,
loader: "babel-loader",
query: {
presets: [ "react" , "es2015" , "stage-2"]
}
}
]
}
};
module.exports = config;
控制台中显示错误:源“http://localhost:8080/app/bundle.js”的加载失败。
编辑:
已添加文件夹列表.. 文件夹路径列表 卷序号为 BE9C-4E51
C:.
| package-lock.json
| package.json
| webpack.config.js
|
+---dist
| | index.html
| |
| \---app
| bundle.js
|
+---node_modules
| <Here the node_modules>
\---src
| index.html
|
\---App
index.js
【问题讨论】:
-
能否分享整个公共路径。您在哪个文件夹中创建了捆绑包?
-
我在编辑的问题中添加了根目录树。
-
提供像
dist或dist/app这样的公共路径,然后将结果回复给我 -
我编辑的配置是 publicPath:"dist\\app\\",但问题出在我使用 dist 作为 publicPath 也没有任何变化。
-
您必须在此处指定文件夹名称的 saame 路径。在这里我认为如果你有 dist 作为你的公共路径 dist 和进入路径并且 dist/app 是公共路径那么我认为 app 将是路径
标签: javascript reactjs webpack