copy custom robots_txt in webpack on compile

This commit is contained in:
jessop 2020-09-20 16:56:06 -04:00 committed by Sean Yesmunt
parent 427f788cf8
commit ba0c22e080
2 changed files with 21 additions and 0 deletions

12
web/src/robots.js Normal file
View file

@ -0,0 +1,12 @@
const fs = require('fs');
const path = require('path');
let robots;
async function getRobots(ctx) {
if (!robots) {
robots = fs.readFileSync(path.join(__dirname, '/../dist/public/robots.txt'), 'utf8');
}
return robots;
}
module.exports = { getRobots };

View file

@ -61,6 +61,15 @@ if (fs.existsSync(CUSTOM_OG_PATH)) {
}); });
} }
const ROBOTS_TXT_PATH = `${CUSTOM_ROOT}/robots.txt`;
if (fs.existsSync(ROBOTS_TXT_PATH)) {
copyWebpackCommands.push({
from: ROBOTS_TXT_PATH,
to: `${DIST_ROOT}/robots.txt`,
force: true,
});
}
let plugins = [ let plugins = [
new WriteFilePlugin(), new WriteFilePlugin(),
new CopyWebpackPlugin(copyWebpackCommands), new CopyWebpackPlugin(copyWebpackCommands),