You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-command-line-reference.md
+12-6
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,9 @@ export default {
18
18
};
19
19
```
20
20
21
-
Typically, it is called `rollup.config.js` or `rollup.config.mjs` and sits in the root directory of your project. If you use the `.mjs` extension or have `type: "module"` in your `package.json` file, Rollup will directly use Node to import it, which is now the recommended way to define Rollup configurations. Note that there are some [caveats when using native Node ES modules](guide/en/#caveats-when-using-native-node-es-modules);
21
+
Typically, it is called `rollup.config.js` or `rollup.config.mjs` and sits in the root directory of your project. Unless the [`--configPlugin`](guide/en/#--configplugin-plugin)or [`--bundleConfigAsCjs`](guide/en/#--bundleconfigascjs) options are used, Rollup will directly use Node to import the file. Note that there are some [caveats when using native Node ES modules](guide/en/#caveats-when-using-native-node-es-modules) as Rollup will observe [Node ESM semantics](https://nodejs.org/docs/latest-v14.x/api/packages.html#packages_determining_module_system).
22
22
23
-
Otherwise, Rollup will transpile and bundle this file and its relative dependencies to CommonJS before requiring it to ensure compatibility with legacy code bases that use ES module syntax without properly respecting [Node ESM semantics](https://nodejs.org/docs/latest-v14.x/api/packages.html#packages_determining_module_system).
24
-
25
-
If you want to write your configuration as a CommonJS module using `require` and `module.exports`, you should change the file extension to `.cjs`, which will prevent Rollup from trying to transpile the CommonJS file.
23
+
If you want to write your configuration as a CommonJS module using `require` and `module.exports`, you should change the file extension to `.cjs`.
26
24
27
25
You can also use other languages for your configuration files like TypeScript. To do that, install a corresponding Rollup plugin like `@rollup/plugin-typescript` and use the [`--configPlugin`](guide/en/#--configplugin-plugin) option:
28
26
@@ -245,7 +243,7 @@ Besides `RollupOptions` and the `defineConfig` helper that encapsulates this typ
245
243
-`Plugin`: A plugin object that provides a `name` and some hooks. All hooks are fully typed to aid in plugin development.
246
244
-`PluginImpl`: A function that maps an options object to a plugin object. Most public Rollup plugins follow this pattern.
247
245
248
-
You can also directly write your config in TypeScript via the [`--configPlugin`](guide/en/#--configplugin-plugin) option. With TypeScript you can import the `RollupOptions` type directly:
246
+
You can also directly write your config in TypeScript via the [`--configPlugin`](guide/en/#--configplugin-plugin) option. With TypeScript, you can import the `RollupOptions` type directly:
249
247
250
248
```typescript
251
249
importtype { RollupOptions } from'rollup';
@@ -480,7 +478,15 @@ Note for Typescript: make sure you have the Rollup config file in your `tsconfig
480
478
"include": ["src/**/*", "rollup.config.ts"],
481
479
```
482
480
483
-
This option supports the same syntax as the [`--plugin`](guide/en/#-p-plugin---plugin-plugin) option i.e., you can specify the option multiple times, you can omit the `@rollup/plugin-` prefix and just write `typescript` and you can specify plugin options via `={...}`. Usingthis option will make Rollup transpile your configuration file to CommonJS first before executing it.
481
+
This option supports the same syntax as the [`--plugin`](guide/en/#-p-plugin---plugin-plugin) option i.e., you can specify the option multiple times, you can omit the `@rollup/plugin-` prefix and just write `typescript` and you can specify plugin options via `={...}`.
482
+
483
+
Using this option will make Rollup transpile your configuration file to an ESmodule first before executing it. To transpile to CommonJS instead, also pass the [`--bundleConfigAsCjs`](guide/en/#--bundleconfigascjs) option.
484
+
485
+
#### `--bundleConfigAsCjs`
486
+
487
+
This option will force your configuration to be transpiled to CommonJS.
488
+
489
+
This allows you to use CommonJS idioms like `__dirname` or `require.resolve`in your configuration even if the configuration itself is written as an ESmodule.
0 commit comments