Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
next.jsを使ったuniversal React 入門
Search
Hori Godai
December 14, 2018
Programming
1
280
next.jsを使ったuniversal React 入門
Hori Godai
December 14, 2018
Tweet
Share
More Decks by Hori Godai
See All by Hori Godai
TypeScript Compiler APIを使って 型のユニットテストをブラウザーで動かす
steelydylan
3
180
エディター付きのReact開発環境を ブラウザーだけで実装した話
steelydylan
9
1.8k
HonoでReact・TypeScriptの実行環境をブラウザー上に作る
steelydylan
1
2.2k
複数ピンをまとめて表示するYahoo!地図用のJavaScriptライブラリをつくりま作りました
steelydylan
1
1.1k
Nuxtでのサーバー、クライアント間データ共有について
steelydylan
0
880
a-blog cmsの静的書き出し機能を使って、 自分のブログを100%静的にした話
steelydylan
0
320
MySQLの GEOMETRY 型とJavaScriptの Geolocation API の活用事例
steelydylan
1
430
アップルップルの新しいオープンソースの紹介
steelydylan
0
480
a-blog cms をよくするために 取り組んだ3つのこと
steelydylan
0
550
Other Decks in Programming
See All in Programming
sappoRo.R #12 初心者セッション
kosugitti
0
280
CloudNativePGを布教したい
nnaka2992
0
110
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
190
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
810
ML.NETで始める機械学習
ymd65536
0
230
Unity Android XR入門
sakutama_11
0
180
バッチを作らなきゃとなったときに考えること
irof
2
520
AIプログラミング雑キャッチアップ
yuheinakasaka
17
4.3k
たのしいSocketのしくみ / Socket Under a Microscope
coe401_
8
1.3k
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
14
4.6k
PEPCは何を変えようとしていたのか
ken7253
2
220
『テスト書いた方が開発が早いじゃん』を解き明かす #phpcon_nagoya
o0h
PRO
8
2.4k
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
370
A designer walks into a library…
pauljervisheath
205
24k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Navigating Team Friction
lara
183
15k
Documentation Writing (for coders)
carmenintech
67
4.6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Designing for humans not robots
tammielis
250
25k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
KATA
mclloyd
29
14k
Building Applications with DynamoDB
mza
93
6.2k
Adopting Sorbet at Scale
ufuk
74
9.2k
Transcript
next.jsを使ったuniversal React入門
自己紹介
自己紹介 @steelydylan React, TypeScript が大好きなフロントエンドエンジニア
目次 Universal JavaScriptとは Reactを使う場合 next.jsがオススメの理由 next.js 説明 next.js高度な使い方 netlifyとは netlifyとの連携
lambda functionとは netlifyの lambda function の利用
Universal JavaScriptとは フロントエンド、サーバーサイドに左右されず一貫して動くJavaScript のこと
Reactの場合 Express.js next.js
Next.jsがおすすめ 理由 TypeScriptを使いやすい フロントエンドとサーバーサイドで処理をわけやすい
next.jsがおすすめ $ npm install --save next react react-dom
next.jsがおすすめ { "scripts": { "dev": "next", "build": "next build", "start":
"next start" } }
next.jsがおすすめ ./pages/index.js を作成し、 export default () => <div>Welcome to next.js!</div>
next.jsがおすすめ これだけ!
next.js高度な設定 TypeScriptを利用 styled‑componentをSSRする
TypeScriptを利用 Babelのpresetを下記のように記述 .babelrc "presets": [ "next/babel", "@zeit/next-typescript/babel" ], next.config.js const
withTypescript = require('@zeit/next-typescript') const withCSS = require('@zeit/next-css') module.exports = withTypescript(withCSS());
styled‑componentをSSR .babelrc "plugins": [ [ "styled-components", { "ssr": true, "displayName":
true, "preprocess": false } ] ]
netlifyとは 静的サイトを簡単に公開することができるサイト gitとの連携が容易で、pushされた時のビルドコマンドを指定することが できる! npm run build など
netlifyとの連携 package.json "scripts": { "build": "next build && npm run
lambda" }
lambda function とは サーバーを必要とせず、必要時にのみ関数を実行できるもの Node.jsなどの言語にも対応している。
netlifyの lambda function の利用 npm install netlify-lambda --save-dev
netlifyの lambda function の利用 package.json "scripts": { "lambda": "netlify-lambda build
functions", "lambda-local": "netlify-lambda serve functions", }
netlifyの lambda function の利用 netlify.tomlの作成 [build] command = "npm run
export" publish = "out" functions = "lambda"
netlifyの lambda function の利用 記述例 exports.handler = async (event, context,
callback) => { return callback(null, { statusCode: 200, headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ test: 'hoge' }) }); };
netlifyの lambda function の利用 run.jsという名前で作成した場合、下のURLでアクセス可能 https://example.com/.netlify/functions/run
実際のgithubレポジトリ https://github.com/steelydylan/next‑starter‑kit