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
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.8k
フィードバックで育てるAI開発
kotaminato
1
110
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
250
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
act2-costs.pdf
sumedhbala
0
100
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
160
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
440
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
220
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.2k
自作OSでスライド発表する
uyuki234
1
3.7k
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
200
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
330
It's Worth the Effort
3n
188
29k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
630
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.1k
GitHub's CSS Performance
jonrohan
1033
470k
A designer walks into a library…
pauljervisheath
211
24k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
GraphQLとの向き合い方2022年版
quramy
50
15k
From π to Pie charts
rasagy
0
230
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
380
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ΤίγεςϜʹߩݙ͍͖ͯ͠·͢