简体   繁体   English

将React-Redux Webpack 2应用程序部署到github页面

[英]Deploying a React-Redux Webpack 2 app to github pages

I have looked at all the documentation of deploy a react app to github pages and none of it has worked or is applicable. 我已经看过将React应用程序部署到github页面的所有文档,但都没有起作用或不适用。 This is driving me up the wall, when Webpack is involved, but I am trying to master Webpack here. 涉及Webpack时,这使我无所适从,但我试图在此处掌握Webpack。

So, I did not originally have a dist folder for my project. 因此,我本来没有用于项目的dist文件夹。

Then I learned you have to put your files in a dist folder and push to gh-pages . 然后,我得知您必须将文件放在dist文件夹中并推送到gh-pages Well, in my Github repo, I do not have that option the way the Github docs say I do. 好吧,在我的Github存储库中,我没有Github文档说的那样的选择。 My only options are master and /docs . 我唯一的选择是master/docs

This is a React 15 app with Redux and Webpack 2. 这是一个带有Redux和Webpack 2的React 15应用程序。

I am getting a blank browser here: https://ldco2016.github.io/JSFaddle/ 我在这里得到一个空白的浏览器: https//ldco2016.github.io/JSFaddle/

It failed to load resource of bundle.js and style.css and I do not know why. 它无法加载bundle.js和style.css的资源,我不知道为什么。 I have yet to have any luck deploying to Github pages. 我还没有运气部署到Github页面。

I tweaked my webpack to include a dist folder, but nothing is being built into it, the folder is empty. 我对Webpack进行了调整,使其包含一个dist文件夹,但是没有内置任何内容,该文件夹为空。

webpack.config.js : webpack.config.js

const path = require('path');

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      loader: 'babel'
    }]
  },
  resolve: {
    root: path.resolve(__dirname, 'src'),
    extensions: ['', '.js', '.jsx']
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

I believe this is the root of my problem, but webpack is still a bit of a mystery to me because of the myriad of configurations you can do. 我相信这是我问题的根源,但是webpack对我来说还是个谜,因为您可以进行多种配置。

So anyone with experience deploying a non create-react-app with webpack to github pages, please reach out to me. 因此,如果您有经验将带有webpack的非create-react-app部署到github页面上,请与我联系。

This continues to be a good working app in my local environment, but there is something I am not understanding in the deployment process. 在我的本地环境中,这仍然是一个很好的工作应用程序,但是在部署过程中有些我不了解。

To be clear, I did not previously have a dist directory when developing locally and after I created a dist directory, none of my static assets were being dumped there. 需要明确的是,在本地开发时,我以前没有dist目录,而在创建dist目录后,没有任何静态资产被转储到那里。

For hosting on GitHub pages you will have to server index.html of built react-app. 为了在GitHub页面上进行托管,您将必须将已构建的react-app的index.html服务器。 So your gh-pages/master should have index.html at the root and not within some folder named as dist. 因此,您的gh-pages / master应该在根目录而不是在名为dist的文件夹中具有index.html。

Your bundle.js is not getting generated because webpack config is incorrect. 由于webpack配置不正确,因此未生成您的bundle.js。 You are not specifying resource type for babel-loader to process. 您没有为babel-loader指定要处理的资源类型。 Please use the below config which I have corrected and tested on my local. 请使用下面的配置,我已经在本地对它进行了更正和测试。

const path = require('path');

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loader: 'babel'
    }]
  },
  resolve: {
    root: path.resolve(__dirname, 'src'),
    extensions: ['', '.js', '.jsx']
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM