If you’re using the Aurelia Webpack Skeleton and you’re developing locally using the development server, then you have probably encountered an issue with pushState and index.html
resolution.
You can see this problem happening on the official skeleton. But essentially you enable pushState in your main.js
or main.ts
file using config.options.pushState = true;
and then you load up the app on port 9000 through http://localhost:9000
Navigating around, you’ll see that the app works. Hitting the /users
route should change your URL to http://localhost:9000/users
and things work. Now what happens if you refresh the page or trying hitting /users
directly? You’ll get gibberish.
What you’re actually seeing is placeholders inside of the index.html
file in your root, not the generated file in your dist
folder. I swear this used to not be a problem, so until this is resolved officially, this is how you fix it.
Open up webpack.config.js
and then inside of the development section, add the following:
{
devServer: {
historyApiFallback: {
index: '/dist/'
}
},
}
You should add this beneath this line that is already present in your Webpack configuration file:
require('@easy-webpack/config-common-chunks-simple')
({appChunkName: 'app', firstChunk: 'aurelia-bootstrap'}),
This will then make everything resolve to your dist
folder and by association, your index.html
file. It isn’t a long term or ideal solution, but this only applies for local development and hopefully a better fix presents itself soon.
That’s if you already did a build. If you wipe your ‘dist’ folder, and just do ‘npm run server’, there won’t be anything in your dist folder, so this hack won’t work. You HAVE to have had already done ‘npm run build:dev’ so that the appropriate files are in the dist folder for this to work.
This has been driving me mad, too, since like you said – it used to work without all this.
Without being 100% sure, I had sort of the same issue after updating packages at some point, and -in my case- it was an issue with the latest Webpack releases.
I fixed that by specifically requesting the last Webpack versions that worked for me in package.json, i.e. :
“webpack”: “2.1.0-beta.22”,
“webpack-dev-server”: “2.1.0-beta.0”
Newest versions had the same issues (reading the webpack index.html configuration texts instead of rendering the components)
This also works for dev server (no dist folder) and build dev/prod just fine. Hopefully it gets properly fixed soon.