【发布时间】:2020-01-11 16:00:25
【问题描述】:
我使用 webpack 创建了一个反应应用程序,并试图将其部署到谷歌应用引擎。该应用程序没有服务器,一切都在浏览器中完成。我之前已经成功部署了简单的 react 应用程序,但我认为 webpack 入口点是目前让我头疼的原因。
我的应用程序部署成功,但导航到 URL 时,我收到 502 bad gateway 错误。查看$gcloud app logs read 时,我没有发现任何问题,我的应用程序已成功编译和构建,谷歌云控制台中的日志也没有任何帮助。我已经尝试将我所有的 devDependencies 移动到依赖项。
我的 webpack 配置:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './src/index.js',
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: [
'@babel/env'
]
}
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|otf)$/,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: path.resolve(__dirname, 'dist/'),
publicPath: '/dist/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.join(__dirname, 'public/'),
port: 8080,
publicPath: 'http://localhost:8080/dist/',
hot: true
},
devtool: "source-map",
plugins: [new webpack.HotModuleReplacementPlugin()]
};
app.yaml:
# [START app_yaml]
env: flex
runtime: nodejs
# [END app_yaml]
package.json:
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --mode development",
"build": "webpack --config webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",
"d3": "^5.11.0",
"file-loader": "^4.2.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-masonry-css": "^1.0.12",
"style-loader": "^0.23.0",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.8.0"
},
"dependencies": {
"bootstrap": "^4.3.1",
"react-hot-loader": "^4.3.11",
"webpack-dev-server": "^3.8.0",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.1",
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"css-loader": "^1.0.0",
"d3": "^5.11.0",
"file-loader": "^4.2.0",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-masonry-css": "^1.0.12",
"style-loader": "^0.23.0"
}
}
【问题讨论】:
标签: reactjs google-app-engine webpack