【发布时间】:2017-03-21 14:08:29
【问题描述】:
我正在尝试使用 webpack 制作一个 react 应用程序,当我尝试运行 npm start 时,它应该加载 http://localhost:3333 但它说无法访问站点,这是我的 webpack 配置:
module.exports = {
entry: './main.js',
output: {
path: '/',
filename: 'index.js'
},
devServer: {
inline: true,
port: 3333
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
}
}
这是来自package.json 的我的脚本对象:"start": "webpack-dev-server"。我已经在全球范围内安装了 webpack 和 webpack-dev-server。检查我得到的下图:
编辑:我的 package.json:
{
"name": "react-app",
"version": "1.0.0",
"description": "sample",
"scripts": {
"start": "webpack-dev-server"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dheeraja00/react-app.git"
},
"author": "Dheeraj Agrawal",
"license": "ISC",
"bugs": {
"url": "https://github.com/dheeraja00/react-app/issues"
},
"homepage": "https://github.comdheeraja00/react-app#readme",
"dependencies": {
"material-design-lite": "^1.2.1",
"react": "^15.3.2"
},
"devDependencies": {
"babel-core": "^6.18.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"css-loader": "^0.25.0",
"file-loader": "^0.9.0",
"node-sass": "^3.10.1",
"raw-loader": "^0.5.1",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.2"
}
}
【问题讨论】:
-
请在运行该命令时在控制台中显示输出。
-
这是它在控制台中没有显示任何内容的问题,当我运行 npm start 时,它会在命令行中提供所有有效输出,说
(webpack)-dev-server/client?http://localhost:3333 3.97 kB {0} [built]但是当我在浏览器中加载它时没有任何反应 -
nothing happens。您的意思是空白页、404 还是“无法访问此站点”?如果您使用 react-router,请检查您的路线。检查js文件是否加载。检查您的 chrome 开发工具的来源和控制台。 -
127.0.0.1:3333 或 0.0.0.0:3333 怎么样?
-
@KhangLu 查看我添加的截图
标签: node.js reactjs npm webpack