Skip to content

Commit

Permalink
docs(cn): resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
waynzh committed Apr 29, 2024
1 parent 9a1e183 commit 2a604f0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 362 deletions.
70 changes: 0 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,77 +48,7 @@
</a>
</p>

<<<<<<< HEAD
## Rollup 贡献者
=======
These commands assume the entry point to your application is named main.js, and that you'd like all imports compiled into a single file named bundle.js.

For browsers:

```bash
# compile to a <script> containing a self-executing function
rollup main.js --format iife --name "myBundle" --file bundle.js
```

For Node.js:

```bash
# compile to a CommonJS module
rollup main.js --format cjs --file bundle.js
```

For both browsers and Node.js:

```bash
# UMD format requires a bundle name
rollup main.js --format umd --name "myBundle" --file bundle.js
```

## Why

Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place [isn't necessarily the answer](https://medium.com/@Rich_Harris/small-modules-it-s-not-quite-that-simple-3ca532d65de4). Unfortunately, JavaScript has not historically included this capability as a core feature in the language.

This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the `--experimental-modules` flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to _write future-proof code_, and you also get the tremendous benefits of...

## Tree Shaking

In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.

For example, with CommonJS, the _entire tool or library must be imported_.

```js
// import the entire utils object with CommonJS
var utils = require('node:utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
```

But with ES modules, instead of importing the whole `utils` object, we can just import the one `ajax` function we need:

```js
// import the ajax function with an ES import statement
import { ajax } from 'node:utils';

var query = 'Rollup';
// call the ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);
```

Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit `import` and `export` statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.

## Compatibility

### Importing CommonJS

Rollup can import existing CommonJS modules [through a plugin](https://github.com/rollup/plugins/tree/master/packages/commonjs).

### Publishing ES Modules

To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the `main` property in your `package.json` file. If your `package.json` file also has a `module` field, ES-module-aware tools like Rollup and [webpack](https://webpack.js.org/) will [import the ES module version](https://github.com/rollup/rollup/wiki/pkg.module) directly.

## Contributors
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. <a href="https://github.com/rollup/rollup/graphs/contributors"><img src="https://opencollective.com/rollup/contributors.svg?width=890" /></a>. If you want to contribute yourself, head over to the [contribution guidelines](CONTRIBUTING.md).

Expand Down
124 changes: 4 additions & 120 deletions docs/command-line-interface/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ rollup --config rollup.config.ts --configPlugin typescript
```javascript twoslash
// rollup.config.js

<<<<<<< HEAD
// 可以是数组(即多个输入源)
=======
// can be an array (for multiple inputs)
// ---cut-start---
/** @type {import('rollup').RollupOptions} */
// ---cut-end---
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
export default {
// 核心输入选项
external,
Expand Down Expand Up @@ -237,16 +233,7 @@ export default commandLineArgs => {
export default commandLineArgs => {
const inputBase = commandLineArgs.input || 'main.js';

<<<<<<< HEAD
// 这会使 Rollup 忽略 CLI 参数
delete commandLineArgs.input;
return {
input: 'src/entries/' + inputBase,
output: { ... }
}
}
=======
// this will make Rollup ignore the CLI argument
// 这会使 Rollup 忽略 CLI 参数
delete commandLineArgs.input;
return {
input: 'src/entries/' + inputBase,
Expand All @@ -255,7 +242,6 @@ export default commandLineArgs => {
}
};
};
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
```

### 填写配置时的智能提示 {#config-intellisense}
Expand Down Expand Up @@ -334,15 +320,9 @@ rollup --config node:my-special-config
import { fileURLToPath } from 'node:url';

export default {
<<<<<<< HEAD
...,
// 为 <currentdir>/src/some-file.js 生成绝对路径
external: [fileURLToPath(new URL('src/some-file.js', import.meta.url))]
=======
/* ..., */
// generates an absolute path for <currentdir>/src/some-file.js
// <currentdir>/src/some-file.js 生成绝对路径
external: [fileURLToPath(new URL('src/some-file.js', import.meta.url))]
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
};
```
Expand Down Expand Up @@ -393,7 +373,6 @@ export default {
许多选项都有等效的命令行标志。在这些情况下,如果你正在使用配置文件,则此处传递的任何参数都将覆盖配置文件。以下是所有支持的选项列表:
```
<<<<<<< HEAD
-c, --config <filename> 使用此配置文件
(如果使用参数但未指定值,则默认为 rollup.config.js
-d, --dir <dirname> 用于块的目录(如果不存在,则打印到 stdout)
Expand Down Expand Up @@ -424,7 +403,7 @@ export default {
--no-esModule 不添加 __esModule 属性
--exports <mode> 指定导出模式(auto、default、named、none)
--extend 扩展由 --name 定义的全局变量
--no-externalImportAssertions"es" 输出中省略导入断言
--no-externalImportAttributes"es" 格式输出中省略导入属性
--no-externalLiveBindings 不生成支持实时绑定的代码
--failAfterWarnings 如果生成的构建产生警告,则退出并显示错误
--filterLogs <filter> 过滤日志信息
Expand All @@ -439,6 +418,7 @@ export default {
--generatedCode.symbols 在生成的代码中使用符号
--hashCharacters <name> 使用指定的字符集来生成文件的哈希值
--no-hoistTransitiveImports 不将中转导入提升到入口块中
--importAttributesKey <name> 使用特定的关键词作为导入属性
--no-indent 不缩进结果
--inlineDynamicImports 使用动态导入时创建单次打包
--no-interop 不包括交互操作块
Expand Down Expand Up @@ -487,102 +467,6 @@ export default {
--watch.onError <cmd>"ERROR" 事件上运行的 Shell 命令
--watch.onStart <cmd>"START" 事件上运行的 Shell 命令
--watch.skipWrite 在监视时不要将文件写入磁盘
=======
-c, --config <filename> Use this config file (if argument is used but value
is unspecified, defaults to rollup.config.js)
-d, --dir <dirname> Directory for chunks (if absent, prints to stdout)
-e, --external <ids> Comma-separate list of module IDs to exclude
-f, --format <format> Type of output (amd, cjs, es, iife, umd, system)
-g, --globals <pairs> Comma-separate list of `moduleID:Global` pairs
-h, --help Show this help message
-i, --input <filename> Input (alternative to <entry file>)
-m, --sourcemap Generate sourcemap (`-m inline` for inline map)
-n, --name <name> Name for UMD export
-o, --file <output> Single output file (if absent, prints to stdout)
-p, --plugin <plugin> Use the plugin specified (may be repeated)
-v, --version Show version number
-w, --watch Watch files in bundle and rebuild on changes
--amd.autoId Generate the AMD ID based off the chunk name
--amd.basePath <prefix> Path to prepend to auto generated AMD ID
--amd.define <name> Function to use in place of `define`
--amd.forceJsExtensionForImports Use `.js` extension in AMD imports
--amd.id <id> ID for AMD module (default is anonymous)
--assetFileNames <pattern> Name pattern for emitted assets
--banner <text> Code to insert at top of bundle (outside wrapper)
--chunkFileNames <pattern> Name pattern for emitted secondary chunks
--compact Minify wrapper code
--context <variable> Specify top-level `this` value
--no-dynamicImportInCjs Write external dynamic CommonJS imports as require
--entryFileNames <pattern> Name pattern for emitted entry chunks
--environment <values> Settings passed to config file (see example)
--no-esModule Do not add __esModule property
--exports <mode> Specify export mode (auto, default, named, none)
--extend Extend global variable defined by --name
--no-externalImportAttributes Omit import attributes in "es" output
--no-externalLiveBindings Do not generate code to support live bindings
--failAfterWarnings Exit with an error if the build produced warnings
--filterLogs <filter> Filter log messages
--footer <text> Code to insert at end of bundle (outside wrapper)
--forceExit Force exit the process when done
--no-freeze Do not freeze namespace objects
--generatedCode <preset> Which code features to use (es5/es2015)
--generatedCode.arrowFunctions Use arrow functions in generated code
--generatedCode.constBindings Use "const" in generated code
--generatedCode.objectShorthand Use shorthand properties in generated code
--no-generatedCode.reservedNamesAsProps Always quote reserved names as props
--generatedCode.symbols Use symbols in generated code
--hashCharacters <name> Use the specified character set for file hashes
--no-hoistTransitiveImports Do not hoist transitive imports into entry chunks
--importAttributesKey <name> Use the specified keyword for import attributes
--no-indent Don't indent result
--inlineDynamicImports Create single bundle when using dynamic imports
--no-interop Do not include interop block
--intro <text> Code to insert at top of bundle (inside wrapper)
--logLevel <level> Which kind of logs to display
--no-makeAbsoluteExternalsRelative Prevent normalization of external imports
--maxParallelFileOps <value> How many files to read in parallel
--minifyInternalExports Force or disable minification of internal exports
--noConflict Generate a noConflict method for UMD globals
--outro <text> Code to insert at end of bundle (inside wrapper)
--perf Display performance timings
--no-preserveEntrySignatures Avoid facade chunks for entry points
--preserveModules Preserve module structure
--preserveModulesRoot Put preserved modules under this path at root level
--preserveSymlinks Do not follow symlinks when resolving files
--no-reexportProtoFromExternal Ignore `__proto__` in star re-exports
--no-sanitizeFileName Do not replace invalid characters in file names
--shimMissingExports Create shim variables for missing exports
--silent Don't print warnings
--sourcemapBaseUrl <url> Emit absolute sourcemap URLs with given base
--sourcemapExcludeSources Do not include source code in source maps
--sourcemapFile <file> Specify bundle position for source maps
--sourcemapFileNames <pattern> Name pattern for emitted sourcemaps
--stdin=ext Specify file extension used for stdin input
--no-stdin Do not read "-" from stdin
--no-strict Don't emit `"use strict";` in the generated modules
--strictDeprecations Throw errors for deprecated features
--no-systemNullSetters Do not replace empty SystemJS setters with `null`
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.annotations Ignore pure call annotations
--treeshake.correctVarValueBeforeDeclaration Deoptimize variables until declared
--treeshake.manualPureFunctions <names> Manually declare functions as pure
--no-treeshake.moduleSideEffects Assume modules have no side effects
--no-treeshake.propertyReadSideEffects Ignore property access side effects
--no-treeshake.tryCatchDeoptimization Do not turn off try-catch-tree-shaking
--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw
--validate Validate output
--waitForBundleInput Wait for bundle input files
--watch.buildDelay <number> Throttle watch rebuilds
--no-watch.clearScreen Do not clear the screen when rebuilding
--watch.exclude <files> Exclude files from being watched
--watch.include <files> Limit watching to specified files
--watch.onBundleEnd <cmd> Shell command to run on `"BUNDLE_END"` event
--watch.onBundleStart <cmd> Shell command to run on `"BUNDLE_START"` event
--watch.onEnd <cmd> Shell command to run on `"END"` event
--watch.onError <cmd> Shell command to run on `"ERROR"` event
--watch.onStart <cmd> Shell command to run on `"START"` event
--watch.skipWrite Do not write files to disk when watching
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
```
以下标志仅通过命令行界面可用。所有其他标志都对应并覆盖其配置文件等效项,请参阅[选项大列表](../configuration-options/index.md)获取详细信息。
Expand Down
36 changes: 9 additions & 27 deletions docs/configuration-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,8 @@ export default {

虽然 CommonJS 输出最初只支持 `require(…)` 语法来引入依赖,但最近的 Node 版本也开始支持 `import(…)` 语法,这是从 CommonJS 文件中引入 ES 模块的唯一方法。如果这个选项默认值为 `true`,表示 Rollup 会在 CommonJS 输出中保持外部依赖以 `import(…)` 表达式动态引入。将值设置为 `false`,以使用 `require(…)` 语法重写动态引入。

<<<<<<< HEAD
```js
// 输入
=======
```js twoslash
// input
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
// 输入
import('external').then(console.log);

// 设置 dynamicImportInCjs 为 true 或不设置的 cjs 输出
Expand Down Expand Up @@ -766,13 +761,8 @@ Promise.resolve()

该选项表示在某些地方和辅助函数中使用 `const` 而不是 `var`。由于代码块的作用域,会使 Rollup 产生更有效的辅助函数。

<<<<<<< HEAD
```js
// 输入
=======
```js twoslash
// input
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
// 输入
export * from 'external';

// 设置 constBindings 为 false 的 cjs 输出
Expand Down Expand Up @@ -940,21 +930,17 @@ exports.foo = foo;

默认情况下,创建多个 chunk 时,入口 chunk 的可传递引入将以空引入的形式被打包。详细信息和背景请查看 ["Why do additional imports turn up in my entry chunks when code-splitting?"](../faqs/index.md#why-do-additional-imports-turn-up-in-my-entry-chunks-when-code-splitting)。该选项的值为 `false` 将禁用此行为。当使用 [`output.preserveModules`](#output-preservemodules) 选项时,该选项会被忽略,使得永远不会取消引入。

<<<<<<< HEAD
### output.inlineDynamicImports {#output-inlinedynamicimports}
=======
### output.importAttributesKey

| | |
| -------: | :----------------------------- |
| Type: | `"with" \| "assert"` |
| CLI: | `--importAttributesKey <name>` |
| Default: | `"assert"` |
| | |
| -----: | :----------------------------- |
| 类型: | `"with" \| "assert"` |
| CLI | `--importAttributesKey <name>` |
| 默认: | `"assert"` |

This determines the keyword set that Rollup will use for import attributes.
该选项决定 Rollup 用于导入属性的关键词集合。

### output.inlineDynamicImports
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
### output.inlineDynamicImports {#output-inlinedynamicimports}

| | |
| -----: | :--------------------------------------------------- |
Expand Down Expand Up @@ -1312,14 +1298,10 @@ function getTranslatedStrings(currentLanguage) {
function manualChunks(id, { getModuleInfo }) {
const match = /.*\.strings\.(\w+)\.js/.exec(id);
if (match) {
<<<<<<< HEAD
const language = match[1]; // 例如 “en”
=======
const language = match[1]; // e.g. "en"
// ---cut-start---
/** @type {string[]} */
// ---cut-end---
>>>>>>> 91352494fc722bcd5e8e922cd1497b34aec57a67
const dependentEntryPoints = [];

// 在这里,我们使用 Set 一次性处理每个依赖模块
Expand Down
Loading

0 comments on commit 2a604f0

Please sign in to comment.