我使用vue-loader来使用webpack构建我的Vue应用程序.我的申请由Firebase提供.

为了搜索引擎优化,我需要为文件机器人服务.我的应用程序根目录下的txt(GET /robots.txt).

如何配置webpack/vue loader来提供此文件?

这是我目前的网页基本配置./config/index.js

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')

module.exports = {
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    productionSourceMap: true,
    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  },
  dev: {
    env: require('./dev.env'),
    port: 8080,
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  }
}

推荐答案

如果我的假设是正确的,那么您正在使用webpack模板中的npm run build命令构建应用程序,创建一个/dist文件夹,并将其部署到Firebase.如果是这样的话,你可以添加一个机器人.txt文件到索引旁边的dist文件夹.这应该行得通.

然而,如果你的目标是更好的SEO,那么根据应用程序的复杂性,可以更好地预呈现页面或使用服务器端呈现.

Vue.js相关问答推荐

VueJS使所有组件崩溃,而不是只有一个

Select 项目后,Vuetify v-select在select后面显示数字1

当try 更新 Vue 3 中的关联数组中的单个元素时,所有值都会更新

Vue3 动态渲染

有没有办法初始化一个保留初始 HTML 的 Vue 对象

Vue-tables-2(vuex)react性不起作用

如何使用 vue.js 和 vue 路由实现当前路由的子菜单的子菜单

Vue.js 中有没有类似Jquery $(document).ready的功能?

使用 azure devops 发布管道部署 Vue.js 应用程序

在 vuejs 中将旧代码修改为 vue router 4

将数据传递给另一条路由上的组件

v-on:submit.prevent 不停止表单提交

Axios-一次发出多个请求(vue.js)

Vuetify 2 个工具栏和 1 个导航抽屉,navigation drawer导航抽屉上方有 1 个工具栏

无法访问数据对象的嵌套属性

使用 Vue-cli,我在哪里声明我的全局变量?

如何告诉 Vue-cli 我的应用程序的入口点在哪里?

动态更改我的 Vue.js SPA 主题的最佳方式?

如何在我的 vue js 中实现无限滚动

Vue.js 无法读取 null 的属性 length长度