😍Trình duyệt không có require, nhưng Node.js thì có. Với Browserify để trình duyệt cũng có (ok)
https://browserify.org/
Example chạy trực tiếp file app.js không được phải build bằng browserify ví dụ thành file bun.js
index.html
dist\app.js
Bundle up your first module
Browsers don't have the require method defined, but Node.js does. With Browserify you can write code that uses require in the same way that you would use it in Node.
Here is a tutorial on how to use Browserify on the command line to bundle up a simple file called main.js along with all of its dependencies:
main.js
Install the uniq module with npm:
Now recursively bundle up all the required modules starting at main.js into a single file called bundle.js with the browserify command:
Browserify parses the AST for require() calls to traverse the entire dependency graph of your project.Drop a single <script> tag into your html and you're done!
PreviousSử dụng RequireJS và AMD để module hóa code JavaScript (ok)NextSử dụng Bower để quản lý các thư viện code trong Laravel (ok)
Last updated