将REACT-webpack应用程序部署到Heroku时,为什么视频和图像文件会出现404错误?

时间:2019-10-07 18:21:43

标签: reactjs heroku webpack

我正在尝试将REACT Webpack应用程序部署到Heroku。 html,js和css文件均已提供,但所有图像和视频文件都显示404s。

我非常确定路径正确,因为视频/图像文件都在本地正确呈现。另外,如您所见,我已经安装了文件加载器,并在webpack.config文件中对其进行了配置。我在下面的文件中显示了一些相关的摘要,很抱歉,这有点混乱。请让我知道我还有其他事情可以分享,以澄清情况。我对heroku还是很陌生,过去真的很难为它部署项目。任何想法或可能的解决方案将不胜感激。

我的控制台消息:

ChefUp-logo.png:1 Failed to load resource: the server responded with a status of 404 (Not Found)
home-icon.png:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Meat_2.mp4:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Meat_1.mp4:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Dessert_1.mp4:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Dessert_2.mp4:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Veg_1.mp4:1 Failed to load resource: the server responded with a status of 404 (Not Found)
Veg_3.mp4:1 Failed to load resource: the server responded with a status of 404 (Not Found)

我的webpack.config.js

var CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');

module.exports = {
  entry: './src/js/main.js',

  output: {
    path: path.join(__dirname, '/dist'),
    filename: 'bundle.js'
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
       }
      },
      {
        test: /\.css$/,
        use: [
           'style-loader',
           'css-loader'
        ]
    },
      {
        test: /\.less$/,
        loader: "style!css!less"
      },
      {
        test: /\.(jpg|png|gif)$/,
        use: [
          'file-loader'
        ]
      },
      {
        test: /\.(mp3|wav|ogg|mp4)$/,
        use: [
          'file-loader'
        ]
    }
    ]
  },

  plugins: [
    new CopyWebpackPlugin([
      { from: './src/index.html' }
    ]),
  ],

  resolve: {
    extensions: ['webpack.js', 'web.js', '.js', '.jsx']
  },

  devServer: {
    inline: true,
    contentBase: './dist',
    port: 5000
  }
};

我的package.json依赖关系和开发依赖关系:

    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.24.1",
    "copy-webpack-plugin": "^4.6.0",
    "css-loader": "^0.26.1",
    "express": "^4.14.0",
    "file-loader": "^4.2.0",
    "less": "^2.7.2",
    "less-loader": "^2.2.3",
    "react": "^16.10.2",
    "react-bootstrap": "^1.0.0-beta.14",
    "react-dom": "^16.10.2",
    "react-strap": "0.0.1",
    "react-youtube": "^7.9.0",
    "reactstrap": "^8.0.1",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7",
    "video-react": "^0.14.1",
    "webpack": "^4.41.0",
    "webpack-dev-server": "^3.8.2"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.41.0",
    "webpack-cli": "^3.3.9",
    "webpack-dev-server": "^3.8.2"
  }
}

主要组件(ChefApp.js)中的路由

    constructor(props) {
        super(props);
        this.state = {
            chefclasses: ["src/videos/Meat_1.mp4", "src/videos/Meat_2.mp4", "src/videos/Dessert_1.mp4", "src/videos/Dessert_2.mp4", "src/videos/Veg_1.mp4", "src/videos/Veg_3.mp4"],
            selectedvideo: false,
            ingredients: [],
            instructions: []
        }

我的server.js

var express = require('express');

var app = express();

app.use(express.static(path.join(__dirname, 'dist')));
app.use(express.static(path.join(__dirname, 'src/js')));
app.set('port', process.env.PORT || 8080);

var server = app.listen(app.get('port'), function() {
  console.log('listening on port ', server.address().port);
});

最后,这些是我文件夹结构中的相关文件:

|--dist
|----bundle.js
|----index.js
|--node_modules
|--src
|----componnents
|------ChefApp.js
|------style.jss
|----images
|----js
|------main.js
|----videos
|----index.html
|--package.json
|--server.js
|--webpack.config.js

很抱歉,如果我共享太多代码,我只是不知道该在哪里找到问题。非常感谢您的帮助。

0 个答案:

没有答案