Webpack 构建未呈现 HTML5 视频

Webpack Build Not Rendering HTML5 Video

-- 我有一个 HTML5 视频可以在本地主机(开发环境)中正确加载。

React 组件

import HomeVideo from '../video/home.mp4';
const Home = () => (
  <div className="home-container">
    <div className='video-container'>
    </div>
    <video autoPlay loop>
      <source src={HomeVideo} type='video/mp4' />
      Your browser does not support the video tag.<a href="https://youtu.be/bgSMpRpObCg" rel="noopener noreferrer" target="_blank">Watch it here</a>
    </video>
  </div>
  </div>    
)
export default Home;

Package.json

"scripts": {
    "start": "webpack-dev-server --devtool eval-source-map --history-api-fallback --open",
    "build": "webpack -p"
  },

我的 webpack.config.js 目前是这样写的: ps:无论有没有注释掉的行,行为都是一样的。在开发中工作,在构建后不工作。

const webpack = require('webpack');

module.exports = {
  entry: `${__dirname}/src/index.js`,
  output: {
    path: `${__dirname}/build`,
    publicPath: '/build/',
    filename: 'bundle.js',
  },


  module: {
    rules: [
      //{ test: /\.html$/, loader: 'html-loader?attrs[]=video:src' },
      //{ test: /\.(mov|mp4)$/, loader: 'url-loader?limit=10000&mimetype=video/mp4' },
      {
        test: /\.(mov|mp4)$/, use: [
          {
            loader: 'file-loader',
            options: {
              name: '[path][name].[ext]'
            }
          }
        ]
      },
      { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
      {
        test: /\.css$/,
        use: ['style-loader', { loader: 'css-loader', options: { minimize: true } }],
      },
      {
        test: /\.(pdf|jpg|png|svg)$/,
        use: {
          loader: "file-loader",
          options: {
            name: "[path][name].[hash].[ext]",
          },
        },
      },
    ]
  },

  plugins: process.argv.indexOf('-p') === -1 ? [] : [
    new webpack.optimize.UglifyJsPlugin({
      output: {
        comments: false,
      },
    }),
  ],
};

**我不知道这是否重要,但这在 GitHub 页上提供。

使用以下 webpack 配置。(取消下面的注释行,从 /\.(mov|mp4)

中删除限制
  { test: /\.html$/, loader: 'html-loader?attrs[]=video:src' },
  { test: /\.(mov|mp4)$/, loader: 'url-loader' },

请勾选与相似的问题类型。

并查看更多关于 url-loader and html-loader 的信息。

希望对您有所帮助!!