Share & grow the worlds knowledge!
We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
1 Answer
<span><<span>script</span> <span>src</span>=<span>"/js/main.js"</span>></span><span></span><span></<span>script</span>></span> <span><<span>script</span> <span>src</span>=<span>"/js/hello.js"</span>></span><span></span><span></<span>script</span>></span> <span><<span>script</span> <span>src</span>=<span>"/js/world.js"</span>></span><span></span><span></<span>script</span>></span>
Như vậy thì điều gì sẽ xảy ra khi các biến hay các hàm ở trong các file bị trùng nhau? Có thể nó sẽ override hoặc bị báo lỗi tuỳ vào trình thông dịch javascript (tuỳ vào browser). Vậy nên webpack đã ra đời để giải quyết việc này, nó sẽ đóng gói các file thành các module riêng kiểu này:
var hello = require('hello') var world = require('world') var main = require('main')
Vậy là mọi vấn đề đã được giả quyết. Tuy nhiên nhược điểm của phương pháp này là khi code với dự án web thông thường thì sẽ hơi mất công khi mỗi lần chỉnh sửa lại file build lại file bundle đang import ở html kiểu:
<span><<span>script</span> <span>src</span>=<span>"/js/all.min.js"</span>></span><span></span><span></<span>script</span>></span>
Và việc debug cũng có phần nào khó khăn khi code bị đóng gói chung vào 1 file bundle nên cũng hơi khó tra cứu.
Thêm 1 điểm nữa là các javascript thông thường giờ sẽ phải chuyển qua dạng viết module để sử dụng được phần exports.
Quay trở lại bundle là gì, thì nó là kết quả của việc đóng gói các module bằng webpack nhé.
-
0
- Reply
- Questions 985
- Answers 2.1K
- Best Answers 124
- Users 447
-
monkey added an answer You can change the pom.xml to:<div class="markdown-block pos... 1711595433000
-
monkey added an answer listen sự kiện của window scroll, check khi gần đến bottom t... 1711443096000
Related Questions
Recent Activities
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm
-
Voted up question. January 9, 2023 at 2:54 pm