2017-07-16 68 views
0

Server.js如何通过server.js通过webpack生成反应bundle.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 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在CMD运行开始启动在本地主机,但说无法GET/并没有别的运行,但是当我传递cmd webpack-dev-server --config webpack.config.js时,它在localhost 8080上运行,并且工作正常!我需要添加serve.js才能在heroku上部署我缺少的东西?

+0

你可以粘贴你的'Procfile'的内容吗? https://devcenter.heroku.com/articles/getting-started-with-nodejs#define-a-procfile –

+0

web:bundle exec unicorn -p $ PORT -c ./config/unicorn.rb –

+0

我失踪的应用程序。 get('*',function(req,res){res.sendFile(path.resolve(__ dirname,'public/index.html')); });在.listen之前我已经添加了这个,但是现在localhost正在运行,但是没有任何UI在DOM上。 –

回答

1

确保您有一个名为Procfile的文件,其中包括web: <command to run your project>。该命令可能是node server.js或其他依赖于Webpack的东西,它具有Production Guide here(可能是webpack -p)。