-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
daiwanxing
committed
Jul 9, 2023
1 parent
147dc3e
commit e811bc6
Showing
4 changed files
with
30 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# rollup 配置项 | ||
|
||
## external | ||
|
||
在 Rollup 中,`external` 属性用于指定哪些模块应该被视为外部依赖项而不被打包进最终的输出文件中。 | ||
|
||
当你在编写一个使用 Rollup 打包的 JavaScript 应用或库时,通常会依赖其他的库或模块。有些模块可能已经在应用程序的构建环境中存在,或者已经在用户的浏览器或服务器环境中可用,这些模块不需要被打包进最终的输出文件中。相反,你希望在输出文件中创建对这些模块的引用,以便在运行时通过外部依赖项加载它们。 | ||
|
||
## global | ||
|
||
当你的项目依赖于一些全局变量,例如在浏览器环境中使用的 jQuery 库或者其他全局对象时,你可以使用 `global` 属性告诉 Rollup 这些全局变量的名称,以便在打包后的代码中引用它们。 | ||
|
||
使用 `global` 属性的好处是,它允许你在打包过程中引用外部全局变量,而不需要将这些全局变量作为模块的依赖项打包进最终的输出文件中。这对于与已经存在于外部环境中的库或对象进行交互非常有用。 | ||
|
||
|
||
`external` 属性用于指定哪些模块应该被视为外部依赖项而不被打包进最终的输出文件中。这些模块通常是你在代码中 import 或 require 的外部库或模块。 | ||
|
||
`global` 属性用于指定全局变量的名称,这些全局变量已经在外部环境中定义,而你希望在打包后的代码中使用它们。这些全局变量通常是在浏览器环境中定义的库或对象。 | ||
|
||
在两种情况下,你都希望在打包后的代码中不包含这些依赖项的实际代码,而是通过引用或访问外部环境来获取它们。这样可以减小最终输出文件的大小,并且允许在运行时动态加载或使用这些外部依赖项。 | ||
|
||
|
||
## name | ||
|
||
对于打出来的包的格式为 `iife` 或者 `umd` 的,是很有必要设置 `name` 属性。这代表了这个包的全局变量。其他脚本可以通过访问 `name` 的值来使用包。 |