Upgrade to Pro — share decks privately, control downloads, hide ads and more …

npmパッケージを作って公開してみよう

Yu Watanabe
October 12, 2018

 npmパッケージを作って公開してみよう

簡単なnpmパッケージの作り方をまとめてみました

Yu Watanabe

October 12, 2018
Tweet

More Decks by Yu Watanabe

Other Decks in Technology

Transcript

  1. ▸ ࣗݾ঺հ ▸ NpmJSͷΞΧ΢ϯτ࡞੒ ▸ ؆୯ͳReactJSύοέʔδͷ࡞੒ ▸ ϓϩδΣΫτ࡞੒ ▸ ίϯϙʔωϯτ࡞੒

    ▸ Ϗϧυ ▸ ϩʔΧϧͰͷ֬ೝ ▸ ެ։ ▸ ύοέʔδ࡞੒ྫ ▸ React Native(Expo)ͷTwitter APIύοέʔδ ▸ React JSͷiTunesϦϯΫύοέʔδ ▸ ·ͱΊ ֓ཁ
  2. ࣗݾ঺հ(1) Θͨͳ΂Ώ͏ ▸ ॴଐ ▸ גࣜձࣾg&h ▸ Web / ΞϓϦΛझຯͰެ։

    ▸ ࢓ࣄ಺༰ ▸ αʔό / ϑϩϯτ / ΞϓϦ / Web ▸ ΞΧ΢ϯτ ▸ Twitter : @hmktsu ▸ Github : @watanabeyu ٕज़ॻయ5ʹͯ React Native(Expo) + FirebaseͷຊΛग़͠·ͨ͠
  3. ▸ npmύοέʔδΛެ։͢Δʹ͸https://www.npmjs.com/ʹొ࿥ඞਢ ▸ ແྉ/༗ྉ/ΤϯλʔϓϥΠζͷ3छྨ ▸ ొ࿥ͨ͠Β$ npm adduserΛ࣮ߦ ▸ username

    / password /emailΛೖྗͯ͠tokenΛొ࿥ ▸ $ npm loginͰ΋OK NPMJSͷΞΧ΢ϯτ࡞੒(1) npmύοέʔδΛ࡞Δલஈ֊ͷ४උ׬ྃ
  4. ؆୯ͳREACTJSύοέʔδͷ࡞੒(6) ʙϩʔΧϧͰ֬ೝʙ ▸ ϩʔΧϧͰ֬ೝ͢Δʹ͸$ npm linkΛ࢖͑͹OK ▸ react-npm-package-sample಺Ͱ·ͣ͸$ npm link

    ▸ ࣍ʹςετ༻ͷϓϩδΣΫτ಺Ͱ$ npm link react-npm-package-sample ϓϩδΣΫτ಺Ͱimport StyledText from ‘react-npm-package-sample’Ͱ֬ೝ
  5. ؆୯ͳREACTJSύοέʔδͷ࡞੒(7) ʙύοέʔδެ։ʙ ▸ $ npm publishΛ͢Ε͹ࣗಈతʹެ։ ▸ You must be

    logged in to publish packages.ͱ͍͏Τϥʔ͕ग़ͨΒ
 $ npm loginͰϩάΠϯΛ͠௚͢͜ͱͰղܾ ▸ .npmignoreΛ࡞͍ͬͯΒͳ͍ϑΝΠϧΛফ͓ͯ͘͜͠ͱΛ๨Εͣʹ ▸ https://www.npmjs.com/package/react-npm-package-sample
  6. ؆୯ͳREACTJSύοέʔδͷ࡞੒(8) ʙमਖ਼ͳͲʙ ▸ मਖ਼ͨ͠৔߹ͷखॱ ▸ ύονΞοϓσʔτ(1.0.xͳͲ) -> $ npm version

    patch ▸ ϚΠφʔΞοϓσʔτ(1.x.0ͳͲ) -> $ npm version minor ▸ ϝδϟʔΞοϓσʔτ(x.0.0ͳͲ) -> $ npm version major खಈͰ΋ίϚϯυೖྗͰ΋໰୊ͳ͠ όʔδϣϯΛมߋͨ͠Β$ npm publish