我试图启动react-js应用程序与节点服务器。目录 结构: MyTodoGET http:// localhost:3000/404(未找到)
---斌/
------ CSS/
------字体/
------ JS/
------的index.html
---源/
------ App.jsx
------ TodoGroup/
文件server.js:
var express=require('express');
var app=express();
app.set('port',(process.env.PORT||3000));
app.use('/',express.static(__dirname));
app.listen(app.get('port'), function() {
\t console.log('Server started: http://localhost:'+app.get('port')+'/');
});
webpack.config:
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var config = module.exports = {
context: __dirname,
entry: {
'App': './sources/App.jsx',
},
output: {
path: './bin/js',
filename: '[name].js'
},
plugins: [
new ExtractTextPlugin('../css/[name].css')
],
\t devServer: {
contentBase: ".",
host: "localhost",
port: 3000
},
\t
module:{
loaders:[ //загрузчики
{
test: /\.jsx?$/, // определяем тип файлов
exclude: /(node_modules)/,
loader: "babel-loader",
query:{
presets:["es2015", "react"]
}
}
]
}
resolve: {
extensions: ['', '.js', '.jsx']
}
}
在浏览器http://localhost:3000/显示了一个错误: GET http://localhost:3000/ 404(未找到)
你的'server.js'在哪里?假设它在'bin /'的父节点中,则更新'app.use('/',express.static(path.join(__ dirname,“bin /”)));'Import'path'。 –
谢谢你,Molda的回答工作 – Olga