Skip to content

Commit

Permalink
generate in webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadPCh committed Jun 12, 2022
1 parent 2126c4d commit a204e84
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ yarn-error.log*

# Sentry
.sentryclirc

public/robots.txt
7 changes: 7 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-robots-txt.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}
}

Expand Down

0 comments on commit a204e84

Please sign in to comment.