Slide 1

Slide 1 text

asukachikaru ॳΊͯͷ୤ create-react-app ΁

Slide 2

Slide 2 text

About me • @asukachikaru • ୆࿷ग़਎ • झຯɿϒϩάͱϙʔτϑΥϦΦαΠτͷॻ͖௚͠
 ɹɹɹesports
 ɹɹɹήʔϜ

Slide 3

Slide 3 text

͖͔͚ͬ React ͸ਓؾ React ײ૝ 8% 12% 8% 72% ܦݧ͋Γɺڵຯ͋Γ ܦݧ͋Γɺڵຯͳ͠ ܦݧͳ͠ɺڵຯ͋Γ ܦݧͳ͠ɺڵຯͳ͠ Ref: state of js 2019 https://2019.stateofjs.com/front-end-frameworks/ Front-end framework ຬ଍౓ 0% 22.5% 45% 67.5% 90% 38% 78% 87% 88% 89% React Svelte Vue Preact Angular

Slide 4

Slide 4 text

͖͔͚ͬ React ·Ͱͷಓ͕௕͔ͬͨ

Slide 5

Slide 5 text

͖͔͚ͬ ΞυόΠεΛ΋Βͬͨ • ʮॳ৺ऀͩͬͨΒ create-react-app Ͱ͍͍͡Όͳ͍ʯ • ͦΕ͔Β޾ͤʹ฻Β͠·ͨ͠ͱ͞ɻΊͰͨ͠ΊͰͨ͠ • create-react-app ͷίϯϑΥʔτκʔϯ͔Βग़ͨ͘ͳͬͨ·Ͱ

Slide 6

Slide 6 text

npm run eject • TL;DR: ͓͢͢Ί͠ͳ͍ (લఏ͋Γ) • create-react-app default script • ύοΫ͞Ε͍ͯΔ babel, webpack, env ͳͲͷઃఆΛղ์ • ෆՄٯత

Slide 7

Slide 7 text

npm run eject

Slide 8

Slide 8 text

npm run eject • npm script ίϚϯυͰ͸ͳ͘ script ϑΝΠϧͰ start ΍ build Λ࣮ߦ • ·ͩ create-react-app ͷείʔϓ͔Β཭Ε͍ͯͳ͍ • ΑΓϓϩδΣΫτΛίϯτϩʔϧ͍ͨ͠ਓʹର͓ͯ͢͢͠Ί͠ͳ͍

Slide 9

Slide 9 text

Do it from scratch • ࣗ෼Ͱ react Λ build ͢Δ؀ڥΛઃఆ • TL;DR: ͓͢͢Ί

Slide 10

Slide 10 text

Do it from scratch Architecture

Slide 11

Slide 11 text

Do it from scratch Dependencies • react • react-dom • webpack • webpack-cli • @babel/core • @babel/preset-react • babel-loader

Slide 12

Slide 12 text

Do it from scratch HTML template node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … Not built by create-react-app …

Slide 13

Slide 13 text

Do it from scratch Basic React App node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … import React from "react"; const App = () => { return (
Hello, world!
; }; export default App; const time = new Date().toLocaleTimeString();
{time}

Slide 14

Slide 14 text

Do it from scratch React entry node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … import React from "react"; import ReactDOM from "react-dom"; import App from "./App"; ReactDOM.render( , document.getElementById("app-root") );

Slide 15

Slide 15 text

Do it from scratch webpack config node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … const path = require("path"); const webpackConfig = { mode: "development", entry: "./src/index.js", output: { path: path.resolve(__dirname, "build"), filename: "react.bundle.js", }, module: { rules: [ { test: /\.jsx?$/, exclude: /node_modules/, use: "babel-loader", }, ], }, ..

Slide 16

Slide 16 text

Do it from scratch webpack config node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … .. resolve: { extensions: [".js", ".jsx", ".json"], }, devServer: { contentBase: path.resolve(__dirname, “public"), port: 3000, }, }; module.exports = webpackConfig;

Slide 17

Slide 17 text

Do it from scratch Babel config node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … { "presets": ["@babel/preset-react"] }

Slide 18

Slide 18 text

Do it from scratch npm script commands build static react.bundle.js index.html node_mobules public index.html favicon.ico … src components/ utils/ … App.jsx index.js package.json webpack.config.js .babelrc … npm start: webpack —-mode development serve npm build: webpack —-mode production —-config webpack.config.js \ && cp ./public/* ./build

Slide 19

Slide 19 text

End This is just the beginning.

Slide 20

Slide 20 text

This is just the beginning • CSS Loader / CSS-in-JS • Env variables • Optimizer • SSR • TypeScript • ….

Slide 21

Slide 21 text

End.