My website doesn't load because the request for bundle.js instead returns the index.html file.
This project is from a few years ago and at the time it worked fine, but I'm trying to get it up and running again and I'm not sure why this is happening now. If anyone can help, I'd really appreciate it!
File structure:
- src
- app
- db
- public
- assets (folder)
- styles (folder)
- index.html
- server
- auth (folder)
- routers (folder)
- server.js
- webpack.config.js
webpack.config.js:
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src/app', 'client.jsx'),
output: {
path: path.resolve(__dirname, 'src/public/build'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.jsx?$/,
include: path.resolve(__dirname, 'src/app'),
loader: 'babel-loader'
}
]
},
devtool: 'source-map'
};
From index.html:
<body>
<div id="app"></div>
<!-- load the app scripts -->
<script src="/build/bundle.js"></script>
</body>
From server.js:
app.use(express.static(path.resolve(__dirname, '../public')));
app.use('*', function (request, response){
response.sendFile(path.resolve(__dirname, '../public', 'index.html'))
})
From package.json:
"scripts": {
"start": "webpack --watch | nodemon --ignore node_modules ./src/server/server.js --exec babel-node"
},
From .babaelrc:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"airbnb"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }],
"react-html-attrs",
"transform-class-properties",
]
}