Javascript 未在Web包中找到bundle.js

Javascript 未在Web包中找到bundle.js,javascript,node.js,express,webpack,Javascript,Node.js,Express,Webpack,学习使用webpack设置MERN堆栈项目。在运行webpack捆绑所有内容并启动express服务器后,我看到bundle.js未找到,并且在控制台中看到localhost:3000/bundle.js 404状态代码。也许我的路径不正确,或者我遗漏了什么 Package.json { "name": "mern_tut", "version": "1.0.0", "description": "", "main": "server.js", "scripts": {

学习使用webpack设置MERN堆栈项目。在运行webpack捆绑所有内容并启动express服务器后,我看到bundle.js未找到,并且在控制台中看到localhost:3000/bundle.js 404状态代码。也许我的路径不正确,或者我遗漏了什么

Package.json

{
  "name": "mern_tut",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "express": "^4.16.1",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "webpack": "^3.6.0"
  }
}
webpack.config.js

const path = require('path');
module.exports = {
  entry: './static/app.js',
  output: {
    path: path.resolve('dist'),
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },


    ]

  }
}
B.法律改革委员会

{
    "presets":[
        "es2015", "react"
    ]
}
server.js

var express = require('express')

var app = express();

app.use(express.static('static'));

var server = app.listen(3000, function() {
    var port = server.address().port;
    console.log("Started server at port", port);
});
app.use(express.static('dist')) 
项目设置

 - dist
    -bundle.js
- node_modules
- static
   -app.js
   -index.html
- .babelrc
- package.json
- server.js
- webpack.config.js

您没有在这里提供bundle.js。将以下内容添加到server.js

app.use(express.static('dist')) 

这是我在项目中使用的解决方案

// server.js
const express = require('express')
const path = require('path')

const app = express()

// serve our static stuff like index.css
app.use(express.static(path.join(__dirname, 'dist')))

// send all requests to index.html so browserHistory in React Router works
app.get('*', function (req, res) {
  res.sendFile(path.join(__dirname, 'dist', 'index.html'))
})

const port = process.env.PORT || 3000
app.listen(port,() => {
   console.log(`App started on port: ${port}`);
});

谢谢,我试过了,现在我得到一个错误,说“无法获取/”请添加路线。app.get('/',function(request,response){response.sendFile(path.resolve(u dirname,'static',index.html'))谢谢!在我的索引中使用'dist'而不是static,并修复bundle.js的不正确路径,效果很好。