diff --git a/.gitignore b/.gitignore index 82086e0d40..95d2ad5c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ yarn-error.log* # Sentry .sentryclirc + +public/robots.txt \ No newline at end of file diff --git a/next.config.js b/next.config.js index 8c6debc618..56c7e7b7bf 100644 --- a/next.config.js +++ b/next.config.js @@ -8,6 +8,7 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }); var pjson = require('./package.json'); +const generateRobotsTxt = require('./scripts/generate-robots-txt'); const moduleExports = withBundleAnalyzer({ // Your existing module.exports @@ -25,6 +26,12 @@ const moduleExports = withBundleAnalyzer({ // ssr and displayName are configured by default styledComponents: true, }, + webpack(config, { isServer }) { + if (isServer) { + generateRobotsTxt(); + } + return config; + }, }); const sentryWebpackPluginOptions = { diff --git a/package.json b/package.json index 4cd84f13f7..14aad2808b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "2.0.8", "private": true, "scripts": { - "prebuild": "./scripts/generate-robots-txt.js", "build": "next build", "dev": "next dev", "lint": "eslint . --ext .ts --ext .tsx", diff --git a/scripts/generate-robots-txt.js b/scripts/generate-robots-txt.js index 4cf34a7746..e885c687db 100644 --- a/scripts/generate-robots-txt.js +++ b/scripts/generate-robots-txt.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); -const publicPath = path.join(__dirname, 'public'); +const publicPath = path.join(__dirname, '..', 'public'); function generateRobotsTxt() { console.log('VERCEL_ENV: ', process.env.VERCEL_ENV); @@ -22,7 +22,7 @@ function generateRobotsTxt() { } public/robots.txt`, ); } catch (error) { - console.log(`Cannot Generate a public/robots.txt`); + console.log(`Cannot Generate a public/robots.txt`, error); } }