2016-11-27 71 views
3

我将基于React Slingshot样板的编译节点站点部署到Github页面。通过npm start可以在本地运行。如何调试404发布节点站点到Github页面?

但是,当我使用babel编译文件并提交到我的github页面库。该网站为main.c5ec540e041525c6d312.js文件返回了404,尽管我可以看到它位于git存储库中。 (从链接致力于公司名称等等,这些将不低于工作)

从GitHub创建的链接是:

https://pages.github.mycompanyname.com/DDM/index.html

而404我得到的是:

https://pages.github.mycompanyname.com/main.c5ec540e041525c6d312.js/

我尝试删除并重新添加回购建议这里无济于事:

How to fix page 404 on Github Page?

问: 如何调试404发布节点网站Github的页面?

这是babel编译后dist文件夹的内容。然后我把它推到了Github Pages repo上,它可以从主分支自动构建网站。但给人的main.js文件404:

enter image description here

我曾尝试编译之前也改变Index.js的browserHistoryhashHistory。作为在GitHub上的网页问题指出browserHistory使用绝对链接,而后者则没有:

import React from 'react'; 
import ReactDom from 'react-dom'; 
import Routes from './routes'; 
import {Router, hashHistory} from 'react-router'; 
import './styles/styles.scss'; 


import appStore from './reducers'; 
import { Provider } from 'react-redux'; 
import { createStore } from 'redux'; 

let store = createStore(appStore); 

require('./images/favicon.ico'); 
let element = document.getElementById('app'); 

ReactDom.render(
    <Provider store={store}> 
     <Router history={hashHistory} routes={Routes.routes} /> 
    </Provider>, element); 

document.body.classList.remove('loading'); 

这是编译index.js文件的链接:

http://hastebin.com/sipimizazu.xml

也要看webpack专业版配置编译。我看到公共路径设置如下:

export default { 
    resolve: { 
    extensions: ['', '.js', '.jsx'] 
    }, 
    debug: true, 
    devtool: 'source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool 
    noInfo: true, // set to false to see a list of every file being bundled. 
    entry: path.resolve(__dirname, 'src/index'), 
    target: 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test 
    output: { 
    path: path.resolve(__dirname, 'dist'), 
    publicPath: '/', 
    filename: '[name].[chunkhash].js' 
    }, 
+0

你把它放在GH-页面分支? –

+0

不,它是在主人和页面生成器被设置为从中拉。 –

+0

你确定该文件签入git? –

回答

0

更改webpack配置中的publicPath修复了404错误。正如我的GitHub的页面进行了位于.../DDM/

我更新了配置以下内容:

output: { 
    path: path.resolve(__dirname, 'dist'), 
    publicPath: '/DDM/', 
    filename: '[name].[chunkhash].js' 
    }, 
+1

嘿,布赖恩,我在将基于反应弹弓的项目部署到GitHub页面时遇到了类似的问题。你能否提供更多有关你如何运作的信息?它看起来像我有相同的设置,但我仍然得到404错误和不正确的路径。你有我可以参考的示例项目吗? – Logan

+0

嗨你的存储库的Github Pages组织的名称是什么?在webpack.env.config.js文件中,publicPath的值又是什么? Github页面使用此公共路径来查找index.js文件,您可能会得到404,因为路径与您的Github组织的名称不匹配。 –

+0

我正在尝试发布到https://lwilli.github.io/WeatherCompare/。 React Slingshot repo中没有webpack.env.config.js文件...我一直在将webpack.config.prod.js中的output.publicPath值设置为'/ WeatherCompare /',但我无法获取任何工作路线 - 只有主页有效。 – Logan

相关问题