2017-12-23 46 views
1

로드/재생할 간단한 비디오를 가져올 수 없기 때문에 webpack 파일을 살펴보기로했습니다. 코드는 다음과 같습니다.로컬 비디오가로드되지 않습니다. Webpack

const autoprefixer = require('autoprefixer'); 
const path = require('path'); 
const webpack = require('webpack'); 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); 
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); 
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); 
const eslintFormatter = require('react-dev-utils/eslintFormatter'); 
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); 
const getClientEnvironment = require('./env'); 
const paths = require('./paths'); 

const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; 
const host = process.env.HOST || '0.0.0.0'; 
const port = parseInt(process.env.PORT, 10) || 3000; 
const publicPath = `${protocol}://${host}:${port}/`; 

const publicUrl = ''; 
const env = getClientEnvironment(publicUrl); 

module.exports = { 
    devtool: 'cheap-module-source-map', 
    entry: [ 
     require.resolve('./polyfills'), 
     require.resolve('webpack-dev-server/client') + `?${publicPath}`, 
     require.resolve('webpack/hot/dev-server'), 
     paths.appIndexJs, 
    ], 
    output: { 
     pathinfo: true, 
     filename: 'static/js/bundle.js', 
     chunkFilename: 'static/js/[name].chunk.js', 
     publicPath: publicPath, 
     devtoolModuleFilenameTemplate: info => 
      path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), 
    }, 
    resolve: { 
     modules: ['node_modules', paths.appNodeModules].concat(
      process.env.NODE_PATH.split(path.delimiter).filter(Boolean) 
     ), 
     extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'], 
     alias: { 
      'react-native': 'react-native-web', 
     }, 
     plugins: [ 
      new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), 
     ], 
    }, 
    module: { 
     strictExportPresence: true, 
     rules: [ 
      { 
       test: /\.(js|jsx|mjs)$/, 
       enforce: 'pre', 
       use: [ 
        { 
         options: { 
          formatter: eslintFormatter, 
          eslintPath: require.resolve('eslint'), 
         }, 
         loader: require.resolve('eslint-loader'), 
        }, 
       ], 
       include: paths.appSrc, 
      }, 
      { 
       oneOf: [ 
        { 
         test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], 
         loader: require.resolve('url-loader'), 
         options: { 
          limit: 10000, 
          name: 'static/media/[name].[hash:8].[ext]', 
         }, 
        }, 
        { 
         test: /\.(js|jsx|mjs)$/, 
         include: paths.appSrc, 
         loader: require.resolve('babel-loader'), 
         options: { 
          cacheDirectory: true, 
         }, 
        }, 
        { 
         test: /\.css$/, 
         use: [ 
          require.resolve('style-loader'), 
          { 
           loader: require.resolve('css-loader'), 
           options: { 
            importLoaders: 1, 
           }, 
          }, 
          { 
           loader: require.resolve('postcss-loader'), 
           options: { 
            ident: 'postcss', 
            plugins:() => [ 
             require('postcss-flexbugs-fixes'), 
             autoprefixer({ 
              browsers: [ 
               '>1%', 
               'last 4 versions', 
               'Firefox ESR', 
               'not ie < 9', // React doesn't support IE8 anyway 
              ], 
              flexbox: 'no-2009', 
             }), 
            ], 
           }, 
          }, 
         ], 
        }, 
        { 
         test: /\.(html)$/, 
         loader: require.resolve('html-loader'), 
        }, 
        { 
         test: /\.mp4$/, 
         use: [ 
          { 
           loader: require.resolve('file-loader'), 
           options: { 
            name: 'static/media/[name].[hash:8].[ext]' 
           } 
          } 
         ] 
        }, 
        { 
         exclude: [/\.js$/, /\.html$/, /\.json$/], 
         loader: require.resolve('file-loader'), 
         options: { 
          name: 'static/media/[name].[hash:8].[ext]', 
         }, 
        }, 
       ], 
      }, 
     ], 
    }, 
    plugins: [ 
     new InterpolateHtmlPlugin(env.raw), 
     new HtmlWebpackPlugin({ 
      inject: true, 
      template: paths.appHtml, 
     }), 
     new webpack.NamedModulesPlugin(), 
     new webpack.DefinePlugin(env.stringified), 
     new webpack.HotModuleReplacementPlugin(), 
     new CaseSensitivePathsPlugin(), 
     new WatchMissingNodeModulesPlugin(paths.appNodeModules), 
     new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), 
    ], 
    node: { 
     dgram: 'empty', 
     fs: 'empty', 
     net: 'empty', 
     tls: 'empty', 
     child_process: 'empty', 
    }, 
    performance: { 
     hints: false, 
    }, 
    target: 'node-webkit', 
}; 

다음은 내 App.js입니다. 나는 중요하지 않은 모든 것을 꺼냈다. mp4 파일에 대한 간단한 호출입니다.

enter image description here

업데이트 1

심지어이 SO question에서이 코드를 사용하려고 해요 :

<video width="1080" height="1920" autoPlay loop src={ AttractLoop } type="video/mp4" /> 

import React, { Component } from 'react'; 
import { curious } from '@curi/react'; 
import AttractLoop from '../../assets/videos/video.mp4'; 

class App extends Component { 
    render() { 
     return (
      <div className="app-container"> 
       <div className="attract-loop"> 
        <video width="1080" height="1920"> 
         <source src={ AttractLoop } type="video/mp4" /> 
        </video> 
       </div> 
      </div> 
     ); 
    } 
} 

export default curious(App); 

그리고 여기 내 코드 관리자의 스크린 샷입니다

업데이트 2

Big Buck Bunny vide o를 다운로드하여 내 비디오가 잘못 인코딩 된 것을 제외합니다. 동일한 결과를 얻으려면 빈 페이지가 필요합니다.

+1

내 첫 번째 추측은 '정적'을 삭제하는 것입니다. 나는 그것이 당신의'output.publicPath'와'output.path'의 일부라고 가정합니다, 그래서 당신은 그것을 필요로하지 않아야합니다. 하지만 어둠 속에서 총을 맞았습니다. 나머지 설정을 보지 않고 말하기가 어렵습니다. 그게 문제가 아니라면'webpack.config.js'의 나머지 부분을 공유 할 수 있습니까? –

+1

전체 파일을 포함하도록 질문을 수정했습니다. –

+0

흠, 설정이 얼핏 보입니다. 나에게 두 가지를 체크 아웃 할 수 있습니까? 먼저 webpack을 실행 한 후 mp4 파일이 실제로'static/media' 디렉토리에 출력되는지 확인하십시오. 둘째, 번들을여십시오. (대용량 파일을 매우 잘 처리 할 때 윈도우에있는 경우 메모장 ++을 사용하는 것이 좋습니다) 해당 mp4 파일의 이름을 검색하십시오. 이 코드 블록을 여기에 공유하면 정보를 얻을 수있는 정보가 충분하지 않습니다. –

답변

1

: 이런 식으로 뭔가를 시도하십시오.

내 Create React App은 사용자가 프로젝트에서 exe 파일을 만들 수있는 플랫폼 인 Nw.js와 혼합되어 있습니다. 나는 https://github.com/naviapps/create-nw-react-app/issues/6에서 NW.js가 mp4를 기본적으로 허용하지 않는다는 것을 알았습니다. 그래서 프로젝트 설정을 받아들이거나 ogv (또는 다른 사람)에게 내 비디오의 형식을 변경해야했습니다.

0

여기서 문제는 webpack.config.js이 미디어를 정적 디렉토리에 출력하도록 설정되어 있다는 것입니다. ExpressJS를 사용하면 정의한 정적 디렉토리를 공용 경로에서 사용하지 않아야합니다. 이 경로는 공개 경로의 루트에 매핑됩니다. 이 문제를 해결하려면 webpack.config.js을 조정하여 여전히이 정적 디렉토리로 출력해야하지만 파일 로더가로드 될 때 파일 이름에 쓰는 것은 아닙니다. @Jonny이 다른 사람을 도움이 될 것입니다 좋은 웹팩 변경 있었더라도, 나는 실제 문제에 대한 답을 배치하고 싶었다

module.exports = { 
    devtool: 'cheap-module-source-map', 
    entry: [ 
    require.resolve('./polyfills'), 
    require.resolve('webpack-dev-server/client') + `?${publicPath}`, 
    require.resolve('webpack/hot/dev-server'), 
    paths.appIndexJs, 
    ], 
    output: { 
    pathinfo: true, 
    filename: 'js/bundle.js', 
    chunkFilename: 'js/[name].chunk.js', 
    // double check that this has it's backslashes in the right place 
    path: path.resolve(__dirname, publicPath + '/static'), 
    publicPath: publicPath', 
    devtoolModuleFilenameTemplate: info => 
     path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), 
    }, 
    resolve: { 
    modules: ['node_modules', paths.appNodeModules].concat(
     process.env.NODE_PATH.split(path.delimiter).filter(Boolean) 
    ), 
    extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'], 
    alias: { 
     'react-native': 'react-native-web', 
    }, 
    plugins: [ 
     new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), 
    ], 
    }, 
    module: { 
    strictExportPresence: true, 
    rules: [ 
     { 
     test: /\.(js|jsx|mjs)$/, 
     enforce: 'pre', 
     use: [ 
      { 
      options: { 
       formatter: eslintFormatter, 
       eslintPath: require.resolve('eslint'), 
      }, 
      loader: require.resolve('eslint-loader'), 
      }, 
     ], 
     include: paths.appSrc, 
     }, 
     { 
     oneOf: [ 
      { 
      test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], 
      loader: require.resolve('url-loader'), 
      options: { 
       limit: 10000, 
       //name: 'static/media/[name].[hash:8].[ext]', 
       name: 'media/[name].[hash:8].[ext]', 
      }, 
      }, 
      { 
      test: /\.(js|jsx|mjs)$/, 
      include: paths.appSrc, 
      loader: require.resolve('babel-loader'), 
      options: { 
       cacheDirectory: true, 
      }, 
      }, 
      { 
      test: /\.css$/, 
      use: [ 
       require.resolve('style-loader'), 
       { 
       loader: require.resolve('css-loader'), 
       options: { 
        importLoaders: 1, 
       }, 
       }, 
       { 
       loader: require.resolve('postcss-loader'), 
       options: { 
        ident: 'postcss', 
        plugins:() => [ 
        require('postcss-flexbugs-fixes'), 
        autoprefixer({ 
         browsers: [ 
         '>1%', 
         'last 4 versions', 
         'Firefox ESR', 
         'not ie < 9', // React doesn't support IE8 anyway 
         ], 
         flexbox: 'no-2009', 
        }), 
        ], 
       }, 
       }, 
      ], 
      }, 
      { 
      test: /\.(html)$/, 
      loader: require.resolve('html-loader'), 
      }, 
      { 
      test: /\.mp4$/, 
      use: [ 
       { 
       loader: require.resolve('file-loader'), 
       options: { 
        //name: 'static/media/[name].[hash:8].[ext]' 
        name: 'media/[name].[hash:8].[ext]' 
       } 
       } 
      ] 
      }, 
      { 
      exclude: [/\.js$/, /\.html$/, /\.json$/], 
      loader: require.resolve('file-loader'), 
      options: { 
       //name: 'static/media/[name].[hash:8].[ext]', 
       name: 'media/[name].[hash:8].[ext]', 
      }, 
      }, 
     ], 
     }, 
    ], 
    }, 
    plugins: [ 
    new InterpolateHtmlPlugin(env.raw), 
    new HtmlWebpackPlugin({ 
     inject: true, 
     template: paths.appHtml, 
    }), 
    new webpack.NamedModulesPlugin(), 
    new webpack.DefinePlugin(env.stringified), 
    new webpack.HotModuleReplacementPlugin(), 
    new CaseSensitivePathsPlugin(), 
    new WatchMissingNodeModulesPlugin(paths.appNodeModules), 
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), 
    ], 
    node: { 
    dgram: 'empty', 
    fs: 'empty', 
    net: 'empty', 
    tls: 'empty', 
    child_process: 'empty', 
    }, 
    performance: { 
    hints: false, 
    }, 
    target: 'node-webkit', 
}; 
+0

작동하지 않습니다. 변경 사항을 추가하면 (정적 제거 및 출력 경로 추가) 서버가 중단됩니다. 그러나 이것은 나를 더 많이 파고 들게했다. webpackDevServer가 이것과 관련이 있습니까? –

+0

설정에 문제가있을 수 있습니다. 개인적으로 webpack-dev-server를 사용하지 않고 멀리 떨어져있는 것을 선호하지만 거기에 문제가있을 수 있습니다. 기본적으로 일어날 수있는 몇 가지 사항이 있습니다. 1. 자산이 원하는 디렉토리에 출력됩니다. 2. 해당 디렉토리는 서버에 의해 공개/정적으로 설정됩니다. 3. 코드가 public/static 디렉토리를 가리키는 올바른 url을 참조하고 있습니다. 이 문제를 해결하고 github에서 공유 할 수 있습니까? (그래서 diffs를 보여줄 수는 있었습니까?) 도움이된다면 내 env에서 자세히 살펴 봐도 괜찮습니다. –

+0

나는 도움을 정말 사랑하고 정말로 감사 할 것입니다! 나는 많은 코드를 가지고있어서 가장 쉬운 것은 Create NW React App (https://github.com/naviapps/create-nw-react-app)을 설치하고 그것을 꺼낸 다음 Big Buck Bunny 비디오 (http : //camendesign.com/code/video_for_everybody/test.html), 로컬에 배치 한 다음 위의 코드를 사용하여 'App.js'에서 비디오를 호출하십시오. 문제가 발생하기 전에 config 파일을 수정하지 않았으므로 모든 것이 새로 설치와 비슷합니다. –