AgoraIO 网页版 + Heroku
AgoraIO Web + Heroku
我正在尝试将 github 存储库 LargeGroupVideoChat-Web-Webpack 推送到 Heroku。
在本地它工作正常,这些脚本在 package.json 文件中:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --config ./scripts --mode development",
"build": "cross-env NODE_ENV=production webpack --config ./scripts --mode production"},
和 index.js 文件中的 webpack 设置:
module.exports = {
entry: {
index: "./src/index.js",
},
devtool: "inline-source-map",
module: loaders,
plugins,
resolve: {
extensions: [ ".js" ],
},
output: {
filename: "[name].[hash].js",
path: path.resolve(__dirname, distPath),
}, ...
但是,在推送到 Heroku 后它崩溃并报错。我使用以下代码添加了 server.js 文件:
const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
// send the user to index html page inspite of the url
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'index.html'));
});
app.listen(port);
它运行正常,但它只提供 index.html 文件,并且没有链接 webpack 包。有没有快速将应用程序推送到 Heroku 的方法?或者我必须以某种方式重写 webpack 设置?
好的,server.js 文件解决了问题(来自 another 存储库):
var path = require('path');
var express = require('express');
var app = express();
app.use(express.static(path.join(__dirname, 'dist')));
app.set('port', process.env.PORT || 8080);
var server = app.listen(app.get('port'), function() {
console.log('listening on port ', server.address().port);
});
我正在尝试将 github 存储库 LargeGroupVideoChat-Web-Webpack 推送到 Heroku。 在本地它工作正常,这些脚本在 package.json 文件中:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --config ./scripts --mode development",
"build": "cross-env NODE_ENV=production webpack --config ./scripts --mode production"},
和 index.js 文件中的 webpack 设置:
module.exports = {
entry: {
index: "./src/index.js",
},
devtool: "inline-source-map",
module: loaders,
plugins,
resolve: {
extensions: [ ".js" ],
},
output: {
filename: "[name].[hash].js",
path: path.resolve(__dirname, distPath),
}, ...
但是,在推送到 Heroku 后它崩溃并报错。我使用以下代码添加了 server.js 文件:
const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
// send the user to index html page inspite of the url
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'index.html'));
});
app.listen(port);
它运行正常,但它只提供 index.html 文件,并且没有链接 webpack 包。有没有快速将应用程序推送到 Heroku 的方法?或者我必须以某种方式重写 webpack 设置?
好的,server.js 文件解决了问题(来自 another 存储库):
var path = require('path');
var express = require('express');
var app = express();
app.use(express.static(path.join(__dirname, 'dist')));
app.set('port', process.env.PORT || 8080);
var server = app.listen(app.get('port'), function() {
console.log('listening on port ', server.address().port);
});