0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

最低限のReact環境立ち上げのメモ

Posted at

事前準備

node,npmをインストールしておく。

Macのローカルで環境構築

create-react-appコマンドで、サンプルアプリを立ち上げるのが便利。
どこのディレクトリで実行しても開発環境localhostを立ち上げるのは問題なさそう。

npx create-react-app react-sample-app

cd react-sample-app

# ローカル開発環境の立ち上げ
npm start

本番用にビルドする

npm run build

作成されたbuild配下のファイルをサーバにアップする。
スクリーンショット 2025-08-17 23.13.33.png

package.jsonでファイルをアップしたディレクトリをhomepageに指定しないと、各種ファイルがルート指定になっていて読み込みに失敗する。

"homepage": "/test/react/", #例

本番サーバの確認

ブラウザでアクセスして確認。
スクリーンショット 2025-08-17 23.12.13.png

CSPエラーが出ているが動作は問題なさそう。

Content Security Policy of your site blocks the use of 'eval' in JavaScript`
The Content Security Policy (CSP) prevents the evaluation of arbitrary strings as JavaScript to make it more difficult for an attacker to inject unathorized code on your site.

To solve this issue, avoid using eval(), new Function(), setTimeout([string], ...) and setInterval([string], ...) for evaluating strings.

If you absolutely must: you can enable string evaluation by adding unsafe-eval as an allowed source in a script-src directive.

⚠️ Allowing string evaluation comes at the risk of inline script injection.

1 件のディレクティブ
ソースの場所	ディレクティブ	ステータス
script-src	ブロック中
0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?