create-react-appでenvroment variable(環境変数)によってnoindex,nofollowなどmetaのタグをindex.htmlに動的に設定する方法

create-react-appでenvroment variable(環境変数)によってnoindex,nofollowなどmetaのタグをindex.htmlに動的に設定する方法

自分でも何言っているか分からなくなってきた笑
DSC_8751
How to set meta tags such as noindex, nofollow in index.html with environment variable with create-react-app

デプロイ先の環境によってindex.htmlを変更したい時の自分でも引くぐらいザックリ解決する方法です。
他の方法として
ちょっと表題とは違いますが、
HtmlWebpackPluginのtemplateを使う(ejs等)とかあるようですが、もうhtmlごと変えちゃえばいいのではとなりました。以下その方法

Since the engineer on the server recently wants to temporarily delete the authentication, he has asked me whether to write such as to dyninically generate noindex, nofollow in index.html

I search for how to dyninically insert meta tag to index.html

Perhaps there is a better way

This is enough as temporary correspondence

create file as「 public/index.test.html」

Insert tags you want to add only during development

edit 「config/paths.js」

「path.js」create-react-appでenvroments value(環境変数)によってnoindex,nofollowなどをmetaタグ設定する方法
「path.js」create-react-appでenvroments value(環境変数)によってnoindex,nofollowなどをmetaタグ設定する方法

result

create-react-appでenvroments value(環境変数)によってnoindex,nofollowなどをmetaタグ設定する方法
create-react-appでenvroments value(環境変数)によってnoindex,nofollowなどをmetaタグ設定する方法

If you run yarn build-dev,  index.test.html is generated ,

On the other hand, if yarn build-prod is executed, index.html is generated

thank you

参照
https://stackoverflow.com/questions/18982228/how-to-add-meta-tag-in-javascript

https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

他のフロント記事
フロントエンド記事
JavaScript練習問題
recomposeと仲良くなりたい
機動戦士FlowType
styled-componentsの使い方
SCSS問題集

プライベート
サイトTOP
私は何者か
instagram
twitter