UNPKG

8.66 kBTypeScriptView Raw
1/**
2 * https://github.com/rollup/plugins/blob/master/packages/commonjs/types/index.d.ts
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file at
6 * https://github.com/rollup/plugins/blob/master/LICENSE
7 */
8export interface RollupCommonJSOptions {
9 /**
10 * A picomatch pattern, or array of patterns, which specifies the files in
11 * the build the plugin should operate on. By default, all files with
12 * extension `".cjs"` or those in `extensions` are included, but you can narrow
13 * this list by only including specific files. These files will be analyzed
14 * and transpiled if either the analysis does not find ES module specific
15 * statements or `transformMixedEsModules` is `true`.
16 * @default undefined
17 */
18 include?: string | RegExp | readonly (string | RegExp)[]
19 /**
20 * A picomatch pattern, or array of patterns, which specifies the files in
21 * the build the plugin should _ignore_. By default, all files with
22 * extensions other than those in `extensions` or `".cjs"` are ignored, but you
23 * can exclude additional files. See also the `include` option.
24 * @default undefined
25 */
26 exclude?: string | RegExp | readonly (string | RegExp)[]
27 /**
28 * For extensionless imports, search for extensions other than .js in the
29 * order specified. Note that you need to make sure that non-JavaScript files
30 * are transpiled by another plugin first.
31 * @default [ '.js' ]
32 */
33 extensions?: ReadonlyArray<string>
34 /**
35 * If true then uses of `global` won't be dealt with by this plugin
36 * @default false
37 */
38 ignoreGlobal?: boolean
39 /**
40 * If false, skips source map generation for CommonJS modules. This will improve performance.
41 * @default true
42 */
43 sourceMap?: boolean
44 /**
45 * Some `require` calls cannot be resolved statically to be translated to
46 * imports.
47 * When this option is set to `false`, the generated code will either
48 * directly throw an error when such a call is encountered or, when
49 * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
50 * configured dynamic require target.
51 * Setting this option to `true` will instead leave the `require` call in the
52 * code or use it as a fallback for `dynamicRequireTargets`.
53 * @default false
54 */
55 ignoreDynamicRequires?: boolean
56 /**
57 * Instructs the plugin whether to enable mixed module transformations. This
58 * is useful in scenarios with modules that contain a mix of ES `import`
59 * statements and CommonJS `require` expressions. Set to `true` if `require`
60 * calls should be transformed to imports in mixed modules, or `false` if the
61 * `require` expressions should survive the transformation. The latter can be
62 * important if the code contains environment detection, or you are coding
63 * for an environment with special treatment for `require` calls such as
64 * ElectronJS. See also the `ignore` option.
65 * @default false
66 */
67 transformMixedEsModules?: boolean
68 /**
69 * Sometimes you have to leave require statements unconverted. Pass an array
70 * containing the IDs or a `id => boolean` function.
71 * @default []
72 */
73 ignore?: ReadonlyArray<string> | ((id: string) => boolean)
74 /**
75 * In most cases, where `require` calls are inside a `try-catch` clause,
76 * they should be left unconverted as it requires an optional dependency
77 * that may or may not be installed beside the rolled up package.
78 * Due to the conversion of `require` to a static `import` - the call is hoisted
79 * to the top of the file, outside of the `try-catch` clause.
80 *
81 * - `true`: All `require` calls inside a `try` will be left unconverted.
82 * - `false`: All `require` calls inside a `try` will be converted as if the `try-catch` clause is not there.
83 * - `remove`: Remove all `require` calls from inside any `try` block.
84 * - `string[]`: Pass an array containing the IDs to left unconverted.
85 * - `((id: string) => boolean|'remove')`: Pass a function that control individual IDs.
86 *
87 * @default false
88 */
89 ignoreTryCatch?:
90 | boolean
91 | 'remove'
92 | ReadonlyArray<string>
93 | ((id: string) => boolean | 'remove')
94 /**
95 * Controls how to render imports from external dependencies. By default,
96 * this plugin assumes that all external dependencies are CommonJS. This
97 * means they are rendered as default imports to be compatible with e.g.
98 * NodeJS where ES modules can only import a default export from a CommonJS
99 * dependency.
100 *
101 * If you set `esmExternals` to `true`, this plugins assumes that all
102 * external dependencies are ES modules and respect the
103 * `requireReturnsDefault` option. If that option is not set, they will be
104 * rendered as namespace imports.
105 *
106 * You can also supply an array of ids to be treated as ES modules, or a
107 * function that will be passed each external id to determine if it is an ES
108 * module.
109 * @default false
110 */
111 esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
112 /**
113 * Controls what is returned when requiring an ES module from a CommonJS file.
114 * When using the `esmExternals` option, this will also apply to external
115 * modules. By default, this plugin will render those imports as namespace
116 * imports i.e.
117 *
118 * ```js
119 * // input
120 * const foo = require('foo');
121 *
122 * // output
123 * import * as foo from 'foo';
124 * ```
125 *
126 * However there are some situations where this may not be desired.
127 * For these situations, you can change Rollup's behaviour either globally or
128 * per module. To change it globally, set the `requireReturnsDefault` option
129 * to one of the following values:
130 *
131 * - `false`: This is the default, requiring an ES module returns its
132 * namespace. This is the only option that will also add a marker
133 * `__esModule: true` to the namespace to support interop patterns in
134 * CommonJS modules that are transpiled ES modules.
135 * - `"namespace"`: Like `false`, requiring an ES module returns its
136 * namespace, but the plugin does not add the `__esModule` marker and thus
137 * creates more efficient code. For external dependencies when using
138 * `esmExternals: true`, no additional interop code is generated.
139 * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
140 * Rollup: If a module has a default export and no named exports, requiring
141 * that module returns the default export. In all other cases, the namespace
142 * is returned. For external dependencies when using `esmExternals: true`, a
143 * corresponding interop helper is added.
144 * - `"preferred"`: If a module has a default export, requiring that module
145 * always returns the default export, no matter whether additional named
146 * exports exist. This is similar to how previous versions of this plugin
147 * worked. Again for external dependencies when using `esmExternals: true`,
148 * an interop helper is added.
149 * - `true`: This will always try to return the default export on require
150 * without checking if it actually exists. This can throw at build time if
151 * there is no default export. This is how external dependencies are handled
152 * when `esmExternals` is not used. The advantage over the other options is
153 * that, like `false`, this does not add an interop helper for external
154 * dependencies, keeping the code lean.
155 *
156 * To change this for individual modules, you can supply a function for
157 * `requireReturnsDefault` instead. This function will then be called once for
158 * each required ES module or external dependency with the corresponding id
159 * and allows you to return different values for different modules.
160 * @default false
161 */
162 requireReturnsDefault?:
163 | boolean
164 | 'auto'
165 | 'preferred'
166 | 'namespace'
167 | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
168 /**
169 * Some modules contain dynamic `require` calls, or require modules that
170 * contain circular dependencies, which are not handled well by static
171 * imports. Including those modules as `dynamicRequireTargets` will simulate a
172 * CommonJS (NodeJS-like) environment for them with support for dynamic and
173 * circular dependencies.
174 *
175 * Note: In extreme cases, this feature may result in some paths being
176 * rendered as absolute in the final bundle. The plugin tries to avoid
177 * exposing paths from the local machine, but if you are `dynamicRequirePaths`
178 * with paths that are far away from your project's folder, that may require
179 * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
180 */
181 dynamicRequireTargets?: string | ReadonlyArray<string>
182}
183
\No newline at end of file