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
Introducing Now and Next.js
Search
Naoyuki Kanezawa
November 13, 2016
Programming
5.6k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introducing Now and Next.js
now と next.js の紹介
Naoyuki Kanezawa
November 13, 2016
More Decks by Naoyuki Kanezawa
See All by Naoyuki Kanezawa
WebSocketの圧縮機能とSocket.IO
nkzawa
5
9.3k
Socket.IO 1.0 Client for Javaの紹介
nkzawa
5
1.8k
Socket.IO 1.0の変更点・内部的な話
nkzawa
20
9.4k
Other Decks in Programming
See All in Programming
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
310
霧の中の代数的エフェクト
funnyycat
1
340
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
570
1B+ /day規模のログを管理する技術
broadleaf
0
130
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
280
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
250
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
310
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
370
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
460
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
290
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
220
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
GitHub's CSS Performance
jonrohan
1033
470k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Technical Leadership for Architectural Decision Making
baasie
3
440
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
590
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Transcript
Introducing Now and Next.js ౦ژNodeֶԂࡇ2016 @nkzawa
ࣗݾհ
@nkzawa Zeit, Inc ॴଐ next.js ϝϯςφ socket.io ϝϯςφ
Zeit ?
None
now micro hyper (چhyperterm) next.js
now micro hyper (چhyperterm) next.js
Next.js
ϢχόʔαϧͳReactΞϓϦͷͨΊͷখ͞ͳϑϨʔϜϫʔΫ
None
Get started 1. next.js ΛΠϯετʔϧ 2. next ίϚϯυΛ࣮ߦ 3. pages
σΟϨΫτϦʹ Reactίϯϙω ϯτΛฦ͢JSϑΝΠϧΛ࡞
ίϚϯυͰ͍͏ͱ $ npm install —save next $ node_modules/.bin/next $ vi
pages/index.js
pages/index.js import React from ‘react’ export default () => (
<div>Hello, world!</div> )
ϑΝΠϧΛURLʹϚοϐϯά pages/index.js -> / pages/about.js -> /about pages/foo/bar.js -> /foo/bar
ࣗಈͰ͜ΕΒ͕ߦΘΕΔ • αʔόϨϯμϦϯά • ίʔυׂ + Ԇಡࠐ • ࠷৽ίʔυࣗಈ࠶ಡࠐ(hot-code reloading)
• babelʹΑΔτϥϯεύΠϧ • webpackʹΑΔ݁߹
ઃఆͷඞཁͳ͠ ͔ͭ ։ൃɺύϑΥʔϚϯεΛ࠷దԽ
SPAͰΑ͋͘Δ • ॳظද͕͍ࣔ • ϖʔδ͕૿͑Δͱॏ͘ͳΔ
Next.jsͷղܾํ๏
αʔόϨϯμϦϯά ॳظදࣔύϑΥʔϚϯε্ɺSEO JSϑΝΠϧΛஔ͚ͩ͘
ϦονͳWebΞϓϦέʔγϣϯͷͨΊͷ7ͭͷݪଇ http://yosuke-furukawa.hatenablog.com/entry/2014/11/14/141415 “αʔόʔ͕ϖʔδΛϨϯμϦϯά͢ΔͷҙͰͳ͍ɻ” “tl;DR: αʔόʔϨϯμϦϯάSEO͚ͩͷͷ͡Όͳ͘ɺੑೳΛ্ͤ͞ΔͨΊͷͷ Ͱ͢ɻʢޙུʣ”
ίʔυׂ + Ԇಡࠐ ϖʔδຖʹ݁߹ϑΝΠϧΛ࡞͠ɺॳظදࣔ࣌ʹෆඞཁͳϞδϡʔϧಡΈࠐ·ͳ͍ɻ ભҠ͕ൃੜͨ͠ॠؒʹॳΊͯɺ࣍ͷίϯϙʔωϯτΛऔಘ͠දࣔ͢Δɻ ϖʔδಡΈࠐΉϞδϡʔϧ͕૿͑ͯɺଞͷϖʔδʹӨڹ͠ͳ͍ɻ
ͦͷଞͷػೳ
CSS glamor ϥΠϒϥϦΛͬͨελΠϧఆٛ - CSS-in-JS: JSͷදݱྗΛϑϧ׆༻ - ίϯϙωϯτຖʹಠཱ: ύϑΥʔϚϯεతʹଞϖʔδӨڹͳ͠ -
vendor prefix ࣗಈ༩ͷαϙʔτ
import React from 'react' import css from 'next/css' const style
= css({ background: ‘red’, ':hover': { background: 'gray' }, '@media (max-width: 600px)': { background: 'blue' } }) export default () => <p className={style}>hi!</p>
Link ίϯϙʔωϯτ pushState ΛͬͨϖʔδભҠ
import React from 'react' import Link from 'next/link' export default
() => ( <div><Link href=“/about”>͜͜</Link>ΛΫϦοΫ</div> )
Head ίϯϙʔωϯτ headλάͷࢠཁૉΛߋ৽
import React from 'react' import Head from 'next/head' export default
() => ( <div> <Head> <title>λΠτϧ</title> <meta charSet="utf-8" /> </Head> <p>hi</p> </div> )
getInitialProps τοϓϨϕϧίϯϙωϯτͷ props Λฦ͢staticϝιουΛఆٛ
IsomorphicʹσʔλΛऔಘ͢Δྫ import React from ‘react' import 'isomorphic-fetch' export default class
extends React.Component { static async getInitialProps () { // CORS͕༗ޮͳAPIʹαʔόɺΫϥΠΞϯτํ͔ΒΞΫηε const res = await fetch(‘http://api.example.com/user/123’) const user = await res.json() return { user } } render () { return <p>hi, {this.props.user.name}!</p> } }
ٞதͷIssue - Θ͔Γ͍͢URLͷ࣮ݱ /users/123 - babel, webpack ͷΧελϚΠζ ৄ͘͠: https://github.com/zeit/next.js#future-directions
Ұ୴·ͱΊ ReactΛ͍ͬͯΕ͙͢ʹ͑Δ Next.jsϑϩϯτΤϯυ։ൃΛָʹ͠·͢!
now
ΠϛϡʔλϒϧͳσϓϩΠαʔϏε
None
Get started 1. now ΛΠϯετʔϧ 2. now ίϚϯυΛ࣮ߦ͢Δ 3. ॳճͷΈϝʔϧʹΑΔϩάΠϯೝূ
ίϚϯυͰ͍͏ͱ $ npm install -g now $ now
package.json { “name”: “app” “scripts”: { “start”: “node server.js” }
}
ϙʔτΛҰͭͪड͚Δ const http = require(‘http’) http.createServer((req, res) => { res.writeHead(200,
{ 'Content-Type': ‘text/plain' }) res.end(‘Hello, world’) }).listen(3000, () => { console.log(‘Ready!’) })
ඞཁͳͷ npm start ͷఆٛͷΈ ͲͷϙʔτΛlistenͯ͠Α͍
શͯͷΞϓϦɺ͜ͷΑ͏ʹಈ࡞͢Δ • ৗʹHTTPS • ඪ४ͰHTTP/2αϙʔτ • Φʔτεέʔϧ • Πϛϡʔλϒϧ
ΠϛϡʔλϒϧɾσϓϩΠ σϓϩΠ͢Δຖʹ৽͍͠URL͕࡞͞ΕΔɻ ྫ͑: my-app-erkgfjtrna.now.sh ݹ͍URLআ͠ͳͯ͘Α͍ɻӬٱʹଘࡏ͠ଓ͚Δɻ
ຊ൪ެ։͢Δ࣌ʹɺΘ͔Γ͍͢ΤΠϦΞεɾυϝΠϯΛઃఆ $ now alias my-app-erkgfjtrna.now.sh my-app.now.sh
• URL͕ৗʹಉ͡ΞϓϦͷঢ়ଶΛද͢ • ߋ৽ϩʔϧόοΫ͕Ұॠ • εςʔδϯάڥ͕ඞཁͳ͘ͳΔ ͳͲͷར
Φʔτεέʔϧ τϥϑΟοΫϦιʔεͷมԽʹԠͯ͡ɺΠϯελϯεΛ૿ݮ τϥϑΟοΫΛෛՙࢄ
θϩͷεέʔϧ ͠Β͘τϥϑΟοΫ͕ͳ͍߹ɺΠϯελϯε͕θϩʹͳΔ ࠶ͼΞΫηε͕͋Εɺ৽ͨʹΠϯελϯε্ཱ͕͕ͪΔ
σʔλͷӬଓԽ Πϯελϯε͕ࣗಈͰੜɺഁغ͞ΕΔͨΊ෦ʹσʔλΛͤͳ͍ ΘΓʹ compose.com ͳͲͷΫϥυɾετϨʔδαʔϏεΛ͏
Dockerfile αϙʔτ package.json ͷΘΓʹ Dockerfile Λ༻ҙͯ͠ɺ $ now ͲΜͳݴޠͰॻ͔ΕͨΞϓϦσϓϩΠՄೳ
੩తαΠταϙʔτ htmlϑΝΠϧը૾ͳͲͷΞηοτΛ༻ҙͯ͠ɺ $ now ࣗಈͰ੩తαΠτ͔Ͳ͏͔ผ͞ΕΔ
ଞʹ • Now.app: σεΫτοϓɾΫϥΠΞϯτ • zeit.world: Free DNS αʔϏε •
now secret: γʔΫϨοτͷཧ
ϚΠΫϩαʔϏε micro ϥΠϒϥϦΛͬͨϢʔεέʔε https://github.com/zeit/micro
microΛͬͨαʔό࣮ const { json } = require(‘micro’) module.exports = async
(req, res) => { // ϦΫΤετϘσΟͷऔಘ const body = await json(req) console.log(body.data) // Ϩεϙϯε return { message: ‘ok’ } }
package.json { “name”: “foo”, “scripts”: { “start”: “micro” }, “dependencies”:
{ “micro”: “*” } }
σϓϩΠ & ΤΠϦΞεઃఆ $ now $ now alias foo-uiafeuzauf.now.sh foo.now.sh
ϚΠΫϩαʔϏε܈Λ࡞ foo.now.sh bar.now.sh baz.now.sh …
API GatewayͰ·ͱΊΔ api.my-app.com/foo -> foo.now.sh api.my-app.com/bar -> bar.now.sh api.my-app.com/baz ->
baz.now.sh …
Serverless ʹ͍ۙੑ࣭ (αʔόཧෆཁɺΦʔτεέʔϧɺؔɺ୯Ұͷؔ৺ࣄ) ʴ just HTTP (no ϩοΫΠϯ)
·ͱΊ now σϓϩΠΛγϯϓϧ͢Δ ˚ Zeit Node.JSΤίγεςϜʹߩݙ͍͖ͯ͠·͢