Slide 1

Slide 1 text

Nuxt.jsͰ
 TypeScriptͱJSXͱJest ੢෢࢙ !@UBLFTIJ@ גࣜձࣾEJ⒎FBTZ
 औక໾$50 (8%@/VMBC

Slide 2

Slide 2 text

੢෢࢙ גࣜձࣾEJ⒎FBTZ
 औక໾$50 !@UBLFTIJ@ 'JSFCBTF 7VF (PMBOH 3VCZ ($1 ϒϩοΫνΣʔϯ EPDLFS /VYU &MJYJS Թઘ ϥϯχϯά -5͓͡͞Μ ಡॻ ম೑͓͡͞Μ

Slide 3

Slide 3 text

/VYUKT

Slide 4

Slide 4 text

/VYUKT w7VFKTΞϓϦέʔγϣϯ։ൃͷ ͨΊͷϑϨʔϜϫʔΫ ✦ ϧʔςΟϯά7VF3PVUFS ✦ ঢ়ଶ؅ཧ7VFY 7VF൛'MVY ✦ 443 ɹʜͳͲ

Slide 5

Slide 5 text

5ZQF4DSJQU

Slide 6

Slide 6 text

5ZQF4DSJQU w+BWB4DSJQUͷεʔύʔηοτ wলུՄೳͳ੩తܕ෇͚ wΫϥεϕʔεΦϒδΣΫτࢦ޲ w/VYUKT7FS͔Β5ZQF4DSJQUαϙʔτ

Slide 7

Slide 7 text

+49

Slide 8

Slide 8 text

+49 wʮ+BWB4DSJQUF9UFOTJPOʯͷུ wςϯϓϨʔτͰ͸ͳ͘ɺ+BWB4DSJQUͷه๏ wओʹ3FBDUͰར༻ render(h: Vue.CreateElement): Vue.VNode { return (

{this.message} {this.name}

) }

Slide 9

Slide 9 text

+49ΩϞ͍ʁ ೥ͷࢲɾɾɾ +49ΩϞͬʂʂ

Slide 10

Slide 10 text

+49ͳͥΩϞ͍ʁ ϩδοΫͱσβΠϯͷ෼཭ ˠ+49ΩϞͬʂʂ ˠ+49͋Γʂʁ ߏ଄ɾݟͨ໨ɾৼΔ෣͍͕ηοτ ίϯϙʔωϯτࢤ޲

Slide 11

Slide 11 text

+FTU

Slide 12

Slide 12 text

+FTU w+BWB4DSJQUͷϢχοτςετπʔϧ w7VF5FTU6UJMTͱ࿈ܞ

Slide 13

Slide 13 text

࣮ࡍʹ࡞ͬͯΈͨ

Slide 14

Slide 14 text

/VYUKTΞϓϦ։ൃ wDSFBUFOVYUBQQΛར༻ɹ˞UTະରԠ $ yarn create nuxt-app ɾɾɾ ? Project name nuxt_ts ? Project description My first-class Nuxt.js project ? Use a custom server framework none ? Choose features to install (Press to select, to toggle all, to invert selection) ? Use a custom UI framework none ? Use a custom test framework jest ? Choose rendering mode Single Page App ? Author name takeshi ? Choose a package manager yarn

Slide 15

Slide 15 text

/VYUKTΞϓϦ։ൃ

Slide 16

Slide 16 text

OVYUUTʹҠߦ wOPEF@NPEVMFTΛ࡟আ $ rm -rf ./node_modules/ $ rm ./yarn.lock "scripts": { "dev": "nuxt-ts", "build": "nuxt-ts build", "start": "nuxt-ts start", "generate": "nuxt-ts generate", "test": "jest" }, "dependencies": { "cross-env": "^5.2.0", "nuxt-ts": "^2.4.5", "vue-property-decorator": "^8.0.0" }, wOVYUΛ࡟আͯ͠OVYUUTΛ௥Ճ QBDBLHFKTPO

Slide 17

Slide 17 text

OVYUUTʹҠߦ wUTDPOpHKTPOΛ௥Ճ { "extends": "@nuxt/typescript", "compilerOptions": { "baseUrl": ".", "experimentalDecorators": true, "noImplicitAny": false, "allowJs": true, "types": [ "@types/node", "@nuxt/vue-app" ] } } UTDPOpHKTPO

Slide 18

Slide 18 text

DPNQPOFOUTͰ +49Λ࢖͏ wUTDPOpHKTPOʹ+49ͷઃఆΛ௥Ճ { "extends": "@nuxt/typescript", "compilerOptions": { "baseUrl": ".", "experimentalDecorators": true, "noImplicitAny": false, "allowJs": true, "module": "commonjs", "jsxFactory": "h", "types": [ "@types/node", "@nuxt/vue-app" ] } } UTDPOpHKTPO

Slide 19

Slide 19 text

DPNQPOFOUTͰ +49Λ࢖͏ wίϯϙʔωϯτΛ࡞੒ import { Vue, Component, Prop } from 'vue-property-decorator' @Component export default class HelloWorld extends Vue { @Prop({ default: 'TypeScript!' }) readonly name!: string message: string = 'Hello, ' render(h: Vue.CreateElement): Vue.VNode { return (

{this.message} {this.name}

) } } DPNQPOFOUT)FMMP8PSMEUTY

Slide 20

Slide 20 text

DPNQPOFOUTͰ +49Λ࢖͏ w1BHFʹ௥Ճ ɾɾɾ ɾɾɾ import HelloWorld from '~/components/HelloWorld.tsx' export default { components: { ɾɾɾ, HelloWorld } } QBHFTJOEFYWVF

Slide 21

Slide 21 text

5ZQF4DSJQUͱ +49Ͱදࣔ

Slide 22

Slide 22 text

+FTUͰςετ

Slide 23

Slide 23 text

wUTKFTUΛ௥Ճ "devDependencies": { "@vue/test-utils": "^1.0.0-beta.27", "babel-core": "7.0.0-bridge.0", "babel-jest": "^24.1.0", "jest": "^24.1.0", "nodemon": "^1.18.9", "ts-jest": "^24.0.0", "vue-jest": "^3.0.3" } QBDBLHFKTPO +FTUΛ 5ZQF4DSJQUͱ +49ʹରԠ

Slide 24

Slide 24 text

wςετ༻ͷUTDPOpHΛ࡞੒ { "extends": "@nuxt/typescript", "compilerOptions": { "baseUrl": ".", "experimentalDecorators": true, "noImplicitAny": false, "allowJs": true, "jsx": "react", "module": "commonjs", "jsxFactory": "h", "types": [ "@types/node", "@nuxt/vue-app" ] } } UTDPOpHUFTUKTPO +FTUΛ 5ZQF4DSJQUͱ +49ʹରԠ w͜ͷઃఆ͕ͳ͍ͱςετ࣌SFOEFS ͰΤϥʔ wͰ΋ɺ͜ͷઃఆ͕͋Δͱը໘ʹϨ ϯμϦϯά͞Εͳ͍ɾɾ

Slide 25

Slide 25 text

+FTUΛ 5ZQF4DSJQUͱ +49ʹରԠ wKFTUDPOpHKTʹ5ZQF4DSJQUͱ+49ͷઃఆ௥Ճ module.exports = { globals: { 'ts-jest': { useBabelrc: true, tsConfigFile: 'tsconfig.test.json' } }, ɾɾɾ moduleFileExtensions: ['js', 'vue', 'json', 'tsx'], transform: { '^.+\\.js$': 'babel-jest', '.*\\.(vue)$': 'vue-jest', "^.+\\.tsx?$": "ts-jest" }, KFTUDPOpHKT wςετ༻ͷUTDPOpHΛࢦఆ

Slide 26

Slide 26 text

+FTUΛ 5ZQF4DSJQUͱ +49ʹରԠ wςετΛ࣮ߦ $ yarn test w੒ޭʂʂ

Slide 27

Slide 27 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ