0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Angularの開発ステップ 初期に入っていないLibraryを入れたい時

Posted at

モチベーション

初期には入っていないlibraryを使いたかった。
※ちなみに使いたかったのは、@angular/cdk 
※drag&dropの挙動をするコンポーネントを作りたい時に上司に聞いたら教えてくれた。

やること

①package.jsonにLibraryを追加する

{
  "name": "task-management",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
// 省略
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.7",
    "@angular/common": "~8.2.7",
    "@angular/compiler": "~8.2.7",
    "@angular/core": "~8.2.7",
    "@angular/forms": "~8.2.7",
    "@angular/platform-browser": "~8.2.7",
    "@angular/platform-browser-dynamic": "~8.2.7",
    "@angular/router": "~8.2.7",
    "bootstrap": "^4.3.1",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1",
    "@angular/cdk": "*" // ←追加
  },
// 省略
}

※最初devDependenciesに追加しようとしていた。
※dependenciesとdevDependenciesの違いがよく分からなかったので調べてみた。
https://qiita.com/chihiro/items/ca1529f9b3d016af53ec
※↑を読んでもピンとこなかったので、同僚に聞いたら以下の答えをもらった。
dependencies:アプリケーションの動作に必要なもの
devDependencies:Buildや開発補助ツールとして開発時に必要なもの
※version指定については、以下を参照
https://qiita.com/chihiro/items/5826678bc9287fb57a28

②npm iをする

package.jsonに書いてあるものを取りに行ってくれる。
tsファイルに@angular/cdkのimport文を書いてもコンパイルエラーは出なくなったよ!

まとめ

【前提】npmインストールをすると、package.jsonにあるものを取って来るよ
1.package.jsonに欲しいlibraryを追加しよう
2.npm iでそいつを取ってこよう

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?