I have been battling with this, but all in vain. I am taking over this Webpack project that needs to have a robots.txt file running from its directory level, but I cannot get its routing to work. I dropped it next to where index.html is served from, but I keep getting Error Cannot Get robots.txt when I try to load or access it.
Is there any documentations or examples showing how to serve robots.txt from a Webpack projects?
Thanks,
Use CopyWebpackPlugin https://webpack.js.org/plugins/copy-webpack-plugin/
$ npm install copy-webpack-plugin --save-dev
In your webpack.config.js file ...
const CopyPlugin = require('copy-webpack-plugin');
...
module.exports = {
plugins: [
new CopyPlugin([
{ from: 'source', to: 'dest' },
{ from: 'other', to: 'public' },
{ from: 'src/robots.txt', to: 'robots.txt' }
]),
],
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With