【问题标题】:Github Pages React App index.html file not in rootGithub Pages React App index.html 文件不在根目录中
【发布时间】:2018-10-03 03:30:33
【问题描述】:

我进行了广泛的研究,但未能找到此问题的答案。我想它可能仍然没有解决!有什么方法可以更改 React 应用程序的路径(在 webpack 中),以便 index.html 文件可以在根目录中,而不是在公共文件夹中?这样我就可以在 github 页面上托管我的投资组合,这需要 index.html 文件位于根目录中。

【问题讨论】:

  • 是的,有可能。你能展示一下你的 webpack 配置吗?
  • const path = require('path') module.exports = { entry: './src/app.js', output: { path: path.join(__dirname, 'public'), filename: 'bundle.js' }, module: { rules: [ { loader: 'babel-loader', test: /\.js$/, exclude: /node_modules/ }, { test: /\.s?css$/, use: [ 'style-loader', 'css-loader' ] } ] }, devServer: { contentBase: path.join(__dirname, 'public') } };@TheReason

标签: html reactjs github public


【解决方案1】:

您可以在webpack 配置文件的输出中将publicPath 指定为root

喜欢

  output: {
    filename: '[name].js',
    publicPath: '/',
},

【讨论】:

  • 这是我的 webpack。我应该如何编辑这个? const path = require('path') module.exports = { entry: './src/app.js', output: { path: path.join(__dirname, 'public'), filename: 'bundle.js' }, module: { rules: [ { loader: 'babel-loader', test: /\.js$/, exclude: /node_modules/ }, { test: /\.s?css$/, use: [ 'style-loader', 'css-loader' ] } ] }, devServer: { contentBase: path.join(__dirname, 'public') } };
  • 尝试在outputdevServer中添加publicPath
猜你喜欢
  • 2021-12-16
  • 1970-01-01
  • 1970-01-01
  • 2022-12-30
  • 1970-01-01
  • 2016-08-15
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多