WordPressのフロントエンドをGatsbyにリプレースした話 / wordpress-gatsby
by
mottox2
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
WordPressͷϑϩϯτΤϯυΛ GatsbyʹϦϓϨʔεͨ͠ 2018.05.21 We Are JavaScripters! @19th - @mottox2 շదͳWebϑϩϯτΤϯυ։ൃΛ࣮ݱ͢Δ
Slide 2
Slide 2 text
@mottox2 • React, Ruby on RailsΛத৺ʹWebαʔϏε։ൃ͍ͯ͠·͢ • Pull RequestͷϨϏϡʔͱٕज़બఆͷ͓ख͍͍ͯ͠·͢ • SPAΛΔ͜ͱ͕ଟ͍͚ͲࠓWordPress։ൃΛޮԽ͢Δ • ϒϩάͬͯ·͢(esa.io + Gatsby) => mottox2.com Freelance web engineer & designer Yuki Takemoto
Slide 3
Slide 3 text
• GatsbyReactjsͷ੩తαΠτδΣωϨʔλʔ • ༷ʑͳσʔλιʔεΛݩʹߴͳ੩తαΠτ͕࡞ΕΔ͜ͱΛઆ໌ͨ͠ • WordPressͷϑϩϯτΤϯυΛGatsbyʹஔ͖͍͑ͨͱ͍͏Λͨ͠ രαΠτΛരͰ࡞ΕΔNetlify + Gatsby https://speakerdeck.com/mottox2/create-fast-site-with-netlify-and-gatsby લ࡞
Slide 4
Slide 4 text
ͭ͘Γ·ͨ͠ • en.kobit.inɻ • WordPressʹ͍ͬͯͨͷΛϑϩϯτΤϯυΛGatsbyʹΓग़ͨ͠ɻ • WordPress REST APIΛͬͯBuild͢Δܗɻ • GitHubͷmasterʹpush͞Εͨ࣌ɺWordPressͰެ։هࣄ͕ฤू͞Εͨ࣌ʹBuild͕ Δɻ • ը૾S3ʹอଘɺimgixʢը૾৴SaaSʣܦ༝Ͱ৴ɻ
Slide 5
Slide 5 text
• ߟ͑Δ͖͜ͱΛݮΒ͢બΛ͢Δ͜ͱa • ՌΞϐʔϧग़དྷΔΑ͏ʹ͓ͯ͘͜͠ͱa WordPressͱGatsbyͦΕ΄ͲॏཁͰ͋Γ·ͤΜɻ ࠓ͍͑ͨ͜ͱ ҎԼͷϙΠϯτΛ͑ΔͱշదͳWebϑϩϯτΤϯυ։ൃ͕ग़དྷΔՄೳੑ͕ߴ͍
Slide 6
Slide 6 text
• 1. දࣔ࠷దԽ • 2. ։ൃڥͰߟ͑Δ͜ͱ͕ଟ͍ • 3. ։ൃ͕͘ΠϥΠϥ͢Δ • 4. WordPress੬ऑੑରԠ Motivation WordPressͷView։ൃɻෆຬʹࢥ͍ͬͯͨ͜ͱɻ
Slide 7
Slide 7 text
• 1. දࣔ࠷దԽ • Plugin͕ೖΔͨͼʹґଘ͢ΔCSS, JS͕૿͖͑ͯͯπϥΠ • ΫϦςΟΧϧϨϯμϦϯάύεͷ࠷దԽ͕͍͠a Motivation
Slide 8
Slide 8 text
• 2. ։ൃڥͰߟ͑Δ͜ͱ͕ଟ͍ • ࢼߦࡨޡͷʹdocker-composeΛ͏։ൃڥΛ࡞ͬͯͨ • WordPressͱMySQLίϯςφཱ͕͕ͭPluginͷಉظ͕͍·͍ͪ Motivation
Slide 9
Slide 9 text
• 3. ։ൃ͕ͯ͘ΠϥΠϥ͢Δ • ϑϩϯτΤϯυJSͰॻ͖͍ͨΤϯδχΞͱͯ͠PHPͰॻ͖ͨ͘ͳ͍ • SCSS, BrowserSync, WebpackͳͲͰ͍͕ͯͨ͠Ϧϩʔυ͕͍ • Α͔͘Βͳ͍ϔϧύʔϝιουΛ͏ඞཁ͕͋Δa • ຊ൪ڥͰ͔͠࠶ݱग़དྷͳ͍ݱ… Motivation
Slide 10
Slide 10 text
• 4. WordPress੬ऑੑରԠ • ίʔϙϨʔταΠτɾΦϯυϝσΟΞͳͲʹΑ͘ΘΕ͍ͯΔɻa • ར༻ऀ͕ଟ͍ͨΊ߈ܸ͞Ε͍͢ɻa • Λ͔͚ͨ͘ͳ͍ͣͳͷʹ͔͔Δɻa • όʔδϣϯΞοϓ࣌ʹϓϥάΠϯ͕ରԠ͍ͯ͠ͳ͔ͬͨΓa Motivation
Slide 11
Slide 11 text
WordPress͡Όͳ͍ͯ͑͘Δͣ • ʑηοτΞοϓ͕͘͠ͳ͍ͬͯ͘ɻa • όοΫΤϯυͷϑϨʔϜϫʔΫʹґଘ͢ΔϑϩϯτΤϯυελοΫͳͲɻa • ϑϩϯτΤϯυελοΫͰॻ͖͍ͨɻa • (αʔόʔαΠυͷݴޠͰॻ͖ͨ͘ͳ͍)a ཁ͢Δʹ… ։ൃ͕͠ΜͲ͍
Slide 12
Slide 12 text
Gatsbyͷಋೖ • Blazing-fastͳ੩తαΠτδΣωϨʔλʔ • Resource HintsʹΑΔઌಡΈɺSPAʹΑΔϖʔδભҠͷߴԽɺCode Splitting ʹΑΔϑΝΠϧׂɺInline CSSͳͲ͕ඪ४ͰରԠɻ • ։ൃڥ1ίϚϯυͰཱͭ • ॻ͘ྔ͕ඇৗʹগͳ্͍ʹίʔυͷ༳Ε͕গͳ͍a • جຊతʹPluginܦ༝ͰDataSourceΛऔಘɺGraphQLͰViewͰ༻ • ॻ͘ͷReactͷViewͱϖʔδͷಈతੜͷϩδοΫͷΈ • ੩తαΠτԽʹΑΔϝϯςφϯείετͷݮa • NetlifyAWS S3ɺGitHub PagesʹϗεςΟϯάग़དྷΔɻ • WordPress͕࿐ग़͠ͳ͍ͷͰ҆৺ɻ
Slide 13
Slide 13 text
• 1. දࣔ࠷దԽ • ViewࣗͰॻ͍ͯɺߴԽ͍͢͠ܗʹɻޙը૾͚ͩ࠷దԽ͢Εૣ͍ɻ • SPA͖ͷϑϨʔϜϫʔΫͳΒ2ϖʔδҎ߱ͷભҠര • 2. ։ൃڥͰߟ͑Δ͜ͱ͕ଟ͍ • `npm run dev` Ͱ಄ͷ͍͍ਓ͕ߟ͑ͨ։ൃڥ͕͑ΔΑ͏ʹͳͬͨɻa • 3. ։ൃ͕͘ΠϥΠϥ͢Δ • όοΫΤϯυ͕ͨ͠ͷͰɺϑϩϯτΤϯυͷJSͷΈͰ։ൃग़དྷΔɻ • 4. WordPress੬ऑੑରԠ • ੩తαΠτʹ͢ΕରԠͷඞཁੑ͕ബΕΔɻa GatsbyͷಋೖͰղܾͨ͜͠ͱ => ߟ͑Δ͜ͱ͕ݮͬͨ
Slide 14
Slide 14 text
GatsbyͷಋೖͰղܾͨ͜͠ͱ ීஈͷงғؾͰ։ൃग़དྷΔɻ
Slide 15
Slide 15 text
• ͳͥΔͷ͔ʁa • ٕͨͩज़తͳϦϓϨʔε͚ͩͩͱՌΛΞϐʔϧͣ͠Β͍a • ఆྔతʹஅͯ͠Β͏a • ίεύͷ͍͍ରԠʢ͜ͷ߹ը૾ʣΛͬͯࣈΛग़͓ͯ͘͠ɻa ଞʹߴԽͷͨΊʹͬͨ͜ͱ
Slide 16
Slide 16 text
ଞʹߴԽͷͨΊʹͬͨ͜ͱ • 1. ը૾มSaaSͷ imgixΛಋೖ • ύϥϝʔλ͚ͭΔͱը૾ॖখͱ͔ϑΥʔϚοτͷมΛͬͯΒ͑Δɻa • background-imagequalityམͱ͢ɺChromeͷ࣌webpΛฦ͢ͳͲ • 2. ը૾ͷLazyload • εΫϩʔϧ͞ΕΔ·Ͱը૾ಡ·ͳ͍ͭɻlazysizes͕͓͢͢Ί • 3. Resource HintsͷରԠ • LighthouseͰࢦఠ͞ΕͨͷͰઃఆͨ͠ɻ • DNSղܾΛࣄલʹͬͯΒ͏ɻ
Slide 17
Slide 17 text
Ͱɺ͏ͪͲ͏͢Ε͍͍ͷʁ • ͦͦϑϩϯτΤϯυΛΓग़͢ඞཁ͕͋Δͷ͔ʁa • Γग़͍ͨ͠߹ʹͲ͏ͬͯΓग़͔͢ʁa • ੩తαΠτʹ͓͚ΔJSϑϨʔϜϫʔΫͷબج४
Slide 18
Slide 18 text
Ͱɺ͏ͪͲ͏͢Ε͍͍ͷʁ • ཧ༝͕ऑ͍ϦϓϨʔεΤϯδχΞͷࣗݾຬʹͳΔՄೳੑ͕͋Δɻa • ͦͷมԽ͕ࣗ͝ͱʹͳΔΑ͏ͳϝϦοτΛ࡞Δͱ͍͍Ͱ͢ɻa • ࠓճతʹେ͖ͳϝϦοτΛಘΒΕΔͱ͍͏͜ͱɻa • ߹ʹΑͬͯɺϞϊϦγοΫͳ··։ൃͨ͠ํ͕ૣ͍ • Ͱ͔͍ΞϓϦέʔγϣϯ͍͠ɻ͍··֦େΛࢭΊΔྗΛɻa • ϝδϟʔͳϑϨʔϜϫʔΫͳΒಉ͡ʹऔΓΜͩਓ͕͍Δͣɻa • ίετͷ͍ΘΓͷબࢶͳ͍͔ʁ • RailsͷWebpackerɺLalavel MixͳͲͷwebpackϥούʔ • ͜ΕΒ͔ΒೖΔͱϞμϯJS։ൃͷงғؾΛαʔόʔαΠυͷਓͨͪʹ͑ Δ͜ͱ͕ग़དྷΔɻ ͦͦϑϩϯτΤϯυΛΓग़͢ඞཁ͕͋Δͷ͔ʁa
Slide 19
Slide 19 text
Ͱɺ͏ͪͲ͏͢Ε͍͍ͷʁ • ΦϯυϝσΟΞ৽نαʔϏεͳͲখ͞ͳαʔϏεͳΒׂͱΓग़͍͢͠ɻ • Write͕΄ͱΜͲͳ͘ɺRead͕େͷΞϓϦέʔγϣϯɻ • େ͖ͳαʔϏεΛॻ͖͑Δͷେมɻa • ৫ͱͯ͠ޭମݧΛ࡞Γ͍͢نͷͷ͔Βணख͢Δɻa • SSR(Server Side Rendering)͕ཁ݅ʹೖΔ͜ͱ͕ଟ͍ɻ • ࣗ࡞ͨ͜͠ͱ͋Δ͚Ͳɺτϥϒϧʹૺ͍ͨ͘ͳ͍ͳΒϑϨʔϜϫʔΫʹͬ ͓ͯ͘ͱ͍͍ͱࢥ͏ɻ • ੩తαΠτ͔nodejsͷαʔόʔΛ༻ҙ͢Δ͔ɻ • αΠτͷੑ࣭ʹΑΔɻߋ৽ස͕ߴ͘ͳ͚Ε੩తαΠτʹ͓ͯ͘͠ͱΑ͍ɻ • ੩తαΠτͩͱߟ͑Δ͜ͱ͕ݮΔͷͰָɻa Γग़͍ͨ͠߹ʹͲ͏ͬͯΓग़͔͢ʁa
Slide 20
Slide 20 text
Ͱɺ͏ͪͲ͏͢Ε͍͍ͷʁ • ੩తαΠτͰࣄΓΔ and React͕ड͚ೖΕΒΕΔ • GatsbyɻReactʹͳΕ͍ͯΔਓͰ͋Ε͓͢͢Ίɻ • ֶशίετগͳ͘ɺओ؍Ͱ͕͢୭͕ॻ͍ͯಉ͡ίʔυʹͳΓ·͢ɻ • কདྷతʹಈతαΠτʹ͢Δ͔ or React͕ड͚ೖΕΒΕͳ͍ • NuxtɻVueɻجຊతʹApplication Framework͕ͩ੩తαΠτ࡞ΕΔɻ • ֶशίετଟগඞཁ͕ͩɺຊͰͷࣄྫɾใ͕ଟ͘ਐΊ͍͢ɻa • MarkdownΛ੩తαΠτԽ͍ͨ͠ • VuePressɻVueͷMarkdownʹಛԽͨ͠੩తαΠτδΣωϨʔλʔɻ ੩తαΠτʹ͓͚ΔJSϑϨʔϜϫʔΫͷબج४
Slide 21
Slide 21 text
շదͳ։ൃମݧΛࢦ͍͖ͯ͠·͠ΐ͏ ޙɺิΛϒϩάͰॻ͔͘͠Εͳ͍ͷͰݟͯͶʂ mottox2.com
Slide 22
Slide 22 text
• WordPressͷهࣄϖʔδ͕ϕʔεɻ • ݻఆϖʔδ͕PHPͰ࣮͞ΕՃ͞Ε͍ͯ͘ɻ • ίʔϙϨʔταΠτͰಉ͡ύλʔϯͷߏΛΑ͘ݟΔɻ Ͳ͏͍͏ঢ়گͩͬͨͷ͔ • WordPressΛ͍ͬͯΔͨΊʹɺଞͷϖʔδPHPʢWordPressʣͰ࣮͢Δඞཁ͕ ͋ͬͨɻ • ࣮WordPress Orientedʹͳ͍ͬͯΔ͕ɺϒϩάهࣄΛ1ίϯςϯπͱ͍͏ߟ͑ํ Λ͢Δͱෆదͩͬͨɻ ࠃ൛ͷWordPress͕WordPressͷهࣄ + αʔϏεհͷPHPϖʔδͱ͍͏ߏͰւ ֎൛ͦ͏ͳΔ͓ͦΕ͕͋ͬͨɻ ͳʹ͕Α͘ͳ͍ͷ͔ ิ