Procfile:快遞/的WebPack未能在dokku和Heroku的
build: npm run prod
web: nodemon server.js
的package.json
"scripts": {
"prod": "NODE_ENV=production webpack -p --config ./webpack.prod.config.js --progress --optimize-dupe"
}
Webpack.prod.config:
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: null,
entry: [
'./assets/js/index'
],
output: {
path: path.join(__dirname, 'public/dist/'),
filename: 'bundle.js',
publicPath: '/public/'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: '"production"' }
})
],
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
include: path.join(__dirname, 'assets/js'),
exclude: path.join(__dirname, 'node_modules/')
},
{
test: /\.css$/,
include: path.join(__dirname, 'assets/css'),
loader: 'style-loader!css-loader'
}
]
}
}
Server.js:
var path = require('path'),
express = require('express'),
app = express(),
port = process.env.PORT || 5000
app.use(express.static(path.join(__dirname, 'public')))
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'))
})
var server = app.listen(port, function() {
var host = server.address().address
console.log('Listening at http://%s:%s', host, port)
})
個
錯誤:
Dokku,502網關錯誤:
2016/03/03 22:43:12 [error] 5419#0: *303 connect() failed (111: Connection refused) while connecting to upstream, client: 185.49.14.190, server: xxx.xxx, request: "GET http://testp3.pospr.waw.pl/testproxy.php HTTP/1.1", upstream: "http://172.17.0.4:5000/testproxy.php", host: "testp3.pospr.waw.pl"
2016/03/03 23:54:58 [error] 5419#0: *305 connect() failed (111: Connection refused) while connecting to upstream, client: 185.49.14.190, server: xxx.xxx, request: "GET http://testp4.pospr.waw.pl/testproxy.php HTTP/1.1", upstream: "http://172.17.0.4:5000/testproxy.php", host: "testp4.pospr.waw.pl"
2016/03/04 00:55:35 [error] 5419#0: *307 connect() failed (111: Connection refused) while connecting to upstream, client: 207.46.13.22, server: xxx.xxx, request: "GET /robots.txt HTTP/1.1", upstream: "http://172.17.0.4:5000/robots.txt", host: "artempixel.com.br"
2016/03/04 00:55:41 [error] 5419#0: *309 connect() failed (111: Connection refused) while connecting to upstream, client: 207.46.13.22, server: xxx.xxx, request: "GET/HTTP/1.1", upstream: "http://172.17.0.4:5000/", host: "artempixel.com.br"
有沒有錯誤,從Heroku的日誌,只在前端:
Uncaught SyntaxError: Unexpected token < - bundle.js:1
npm run prod
應/public/dist/
創建一個文件,如它在我的本地機器上執行,但是這個目錄不存在於heroku實例或dokku實例中,沒有錯誤顯示它未能創建它,但是如果我嘗試heroku run --app app mkdir public/dist
它將會是sil一旦失敗,就好像我嘗試訪問它剛創建的目錄不存在一樣。我也嘗試手動運行npm run prod
,它很成功,沒有創建dir,沒有出現錯誤。
我相信還有什麼我Express服務器正試圖成爲一個問題,我的bundle.js
正被服務index.html
,我不知道這是否是其中不存在bundle.js
服務,或者,即使問題有,app.get('*')
已被錯誤配置,並盲目服務index.html
。
我只是想要一個靜態index.html文件來服務我的bundle.js,所以React可以接管並做它的事情,這似乎與heroku不可能,所以我試圖楔入一個表達式服務器之間,有任何想法嗎?
嗨,你是如何解決這個問題的?我有一個類似的問題:http://stackoverflow.com/questions/44022938/heroku-deployment-browser-console-error-uncaught-syntaxerror-unexpected-token – Coder1000