로봇 서비스 방법Vue 앱의 txt
웹 팩을 사용하여 Vue 앱을 빌드할 때 vue-loader를 사용합니다.내 지원서는 파이어베이스에서 제공한다.
SEO를 위해 파일 로봇을 서비스해야 합니다.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
}
}
VueJS v3 빌드 명령어는 /public에 있는 모든 것을 최종 dist/에 복사합니다.따라서 최종 배포에 필요한 추가 파일에는 공용/폴더를 사용하십시오.
제가 추측하는 것이 맞다면, 당신은 웹팩 템플릿에서 npm run build 명령을 사용하여 /dist 폴더를 만들고 Firebase에 전개하고 있습니다.그런 경우 로봇을 추가하면 됩니다.txt 파일을 인덱스 옆에 있는 dist 폴더에 저장합니다.그러면 되겠군요.
그러나 SEO가 더 나은 경우, 애플리케이션의 복잡성에 따라 페이지를 미리 렌더링하거나 서버 사이드 렌더링을 사용하는 것이 더 나을 수 있습니다.
MEVN 케이스
MEVN은 MongoDB, Express, Vue.js 및 Node.js의 약자입니다.
프런트엔드로 Vue.js를 사용하고 백엔드 및 RESTful API 서버로 Node.js를 사용하는 경우 로봇을 사용할 수 있습니다.txt를 Vue.js에 넣습니다./static/폴더입니다.Vue.js 프로젝트 구조는 다음과 같습니다.
그런 다음 로봇에 서비스를 제공하기 위해 Express Routing(고속 라우팅)을 다음과 같이 구성할 수 있습니다.txt 파일:
app.use('/robots.txt', express.static(path.join(__dirname, 'dist/static/robots.txt')));
(주의: Dist 폴더는 Vue.js 프로젝트를 작성할 때마다 새로 생성됩니다.npm run build그리고 이 접근방식을 통해 로봇을 추가할 필요가 없어집니다.txt 파일을 빌드 후 매번 dist 폴더에 저장합니다.
언급URL : https://stackoverflow.com/questions/49003867/how-to-serve-robots-txt-for-a-vue-app
'programing' 카테고리의 다른 글
| Java에서 hashCode의 용도는 무엇입니까? (0) | 2022.07.06 |
|---|---|
| C기준은 true 값을 0 또는 1로 명시하고 있습니까? (0) | 2022.07.06 |
| C에서의 & & 운영이란? (0) | 2022.07.05 |
| 왜 C++ rand()는 같은 크기의 숫자만 생성하는 것 같습니까? (0) | 2022.07.05 |
| Java에서는 Arrays.equals와 동등합니다. (0) | 2022.07.05 |