-1

I have researched extensively and have not been able to find an answer to this issue. I’m thinking it might still not be solved! Is there any way to change the path of a React app (in webpack) so that the index.html file can be in the root, and not in a public folder? This would be so I can host my portfolio on github pages, which requires the index.html file to be in the root.

sxiong
  • 9
  • 1
  • Yes its possible. Can you show yous webpack config? – The Reason Apr 23 '18 at 07:04
  • `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 – sxiong Apr 24 '18 at 16:32

1 Answers1

3

You can assign the publicPath as root in output in webpack config file

like

  output: {
    filename: '[name].js',
    publicPath: '/',
},
Praveen Kumar
  • 1,966
  • 1
  • 9
  • 16
  • Here is my webpack. How should I edit this? `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') } };` – sxiong Apr 24 '18 at 16:33
  • try to add the `publicPath` in `output` and in `devServer` as well – Praveen Kumar Apr 24 '18 at 17:03