Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

ความแตกต่างระหว่าง Bower และ npm ใน JavaScript


  npm

npm ใช้โดยทั่วไปสำหรับจัดการโมดูล Node.js และทำ nested dependency tree ทำงานสำหรับ front-end และใช้สำหรับ developer tools เช่น Grunt, CoffeeScript ฯลฯ

โดยไม่ใช้ nested dependencies ควบคุม dependency conflicts ได้ยาก ดังนั้นการใช้ npm จึงพิสูจน์แล้วว่าดี

สิ่งที่คุณเพิ่มใน Node โครงสร้างเป็นโมดูล ในการใช้ NPM สำหรับ browser-side dependencies คุณจะจัดโครงสร้างโค้ดเหมือน Node

โครงสร้าง dependency:

project root [node_modules] -> dependency P -> dependency Q [node_modules] -> dependency P -> dependency R [node_modules] -> dependency Q [node_modules] -> dependency P -> dependency S

Bower

Bower ต้องการ flat dependency tree และใช้สำหรับ front end เหมาะสำหรับ front-end packages

โหลดไฟล์ JavaScript ธรรมดาเหมือนเพิ่มใน <script>...</script> ใน <head> tag

เพิ่มประสิทธิภาพสำหรับ front-end และใช้ flat dependency tree ต้องการเพียง single version สำหรับแต่ละ package สุดท้ายลด page load ให้น้อยที่สุด

หมายเหตุ: Bower ตอนนี้ deprecated แล้ว

โครงสร้าง dependency:

project root [bower_components] -> dependency P -> dependency Q // wants P -> dependency R // wants Q and R -> dependency S