我一直在为此奋斗,但徒劳无功。我正在接管这个Webpack项目,该项目需要从其目录级别运行robots.txt文件,但是我无法使其路由正常工作。我将其放置在提供index.html的位置旁边,但是尝试加载或访问它时,我始终收到错误无法获取robots.txt。
是否有任何文档或示例显示了如何从Webpack项目中提供robots.txt?
谢谢,
使用CopyWebpackPlugin https://webpack.js.org/plugins/copy-webpack-plugin/
$ npm install copy-webpack-plugin --save-dev
在您的webpack.config.js文件中...
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' }
]),
],
};