Node.js 如何通过server.js通过webpack生成react bundle.js?
Server.jsNode.js 如何通过server.js通过webpack生成react bundle.js?,node.js,reactjs,express,webpack,react-router,Node.js,Reactjs,Express,Webpack,React Router,Server.js var express = require('express'); app.use(express.static('public')); app.listen(PORT, function () { console.log('Express server is up on port ' + PORT); }); Webpack.config.js var path = require('path'); var webpack = require('webpack'
var express = require('express');
app.use(express.static('public'));
app.listen(PORT, function () {
console.log('Express server is up on port ' + PORT);
});
Webpack.config.js
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractSass = new ExtractTextPlugin({
});
// const autoprefixer = require('autoprefixer');
module.exports = {
entry: path.resolve(__dirname, 'src', 'Main.js'),
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-1'],
plugin
s: ["react-html-attrs"]
}
}
, {
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
loader: 'url-loader?limit=10000',
},
{
test: /masonry|imagesloaded|fizzy\-ui\-utils|desandro\-|outlayer|get\-size|doc\-ready|eventie|eventemitter/,
loader: 'imports-loader?define=>false&this=>window'
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"]
}]
},
plugins: [
extractSass
],
resolve: {
extensions: ['.js', '.jsx', '.css', '.scss'],
},
devServer: {
historyApiFallback: true,
contentBase: './',
}
};
我正在尝试在Heroku上部署,但在此之前,当我通过npm start在cmd上运行时,它会在localhost上启动,但说不能获取/并且没有其他运行,但当我传递cmd webpack dev server-config webpack.config.js时,它会在localhost 8080上运行,工作正常!在heroku上部署之前,我需要添加serve.js。我缺少什么?请确保您有一个名为Procfile的文件,其中包含web:。该命令可能是node server.js或其他依赖于Webpack的命令,它可能有一个Webpack-p.您能粘贴文件的内容吗?web:bundle exec unicorn-p$PORT-c./config/unicorn.rbI缺少app.get'*',functionreq,res{res.sendFilepath.resolve_udirname',public/index.html';};听着,我已经添加了这个,但是现在localhost正在运行,但是DOM上没有任何UI。