UNPKG

7.71 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 minimatch 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 minimatch 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 * Controls how to render imports from external dependencies. By default,
76 * this plugin assumes that all external dependencies are CommonJS. This
77 * means they are rendered as default imports to be compatible with e.g.
78 * NodeJS where ES modules can only import a default export from a CommonJS
79 * dependency.
80 *
81 * If you set `esmExternals` to `true`, this plugins assumes that all
82 * external dependencies are ES modules and respect the
83 * `requireReturnsDefault` option. If that option is not set, they will be
84 * rendered as namespace imports.
85 *
86 * You can also supply an array of ids to be treated as ES modules, or a
87 * function that will be passed each external id to determine if it is an ES
88 * module.
89 * @default false
90 */
91 esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
92 /**
93 * Controls what is returned when requiring an ES module from a CommonJS file.
94 * When using the `esmExternals` option, this will also apply to external
95 * modules. By default, this plugin will render those imports as namespace
96 * imports i.e.
97 *
98 * ```js
99 * // input
100 * const foo = require('foo');
101 *
102 * // output
103 * import * as foo from 'foo';
104 * ```
105 *
106 * However there are some situations where this may not be desired.
107 * For these situations, you can change Rollup's behaviour either globally or
108 * per module. To change it globally, set the `requireReturnsDefault` option
109 * to one of the following values:
110 *
111 * - `false`: This is the default, requiring an ES module returns its
112 * namespace. This is the only option that will also add a marker
113 * `__esModule: true` to the namespace to support interop patterns in
114 * CommonJS modules that are transpiled ES modules.
115 * - `"namespace"`: Like `false`, requiring an ES module returns its
116 * namespace, but the plugin does not add the `__esModule` marker and thus
117 * creates more efficient code. For external dependencies when using
118 * `esmExternals: true`, no additional interop code is generated.
119 * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
120 * Rollup: If a module has a default export and no named exports, requiring
121 * that module returns the default export. In all other cases, the namespace
122 * is returned. For external dependencies when using `esmExternals: true`, a
123 * corresponding interop helper is added.
124 * - `"preferred"`: If a module has a default export, requiring that module
125 * always returns the default export, no matter whether additional named
126 * exports exist. This is similar to how previous versions of this plugin
127 * worked. Again for external dependencies when using `esmExternals: true`,
128 * an interop helper is added.
129 * - `true`: This will always try to return the default export on require
130 * without checking if it actually exists. This can throw at build time if
131 * there is no default export. This is how external dependencies are handled
132 * when `esmExternals` is not used. The advantage over the other options is
133 * that, like `false`, this does not add an interop helper for external
134 * dependencies, keeping the code lean.
135 *
136 * To change this for individual modules, you can supply a function for
137 * `requireReturnsDefault` instead. This function will then be called once for
138 * each required ES module or external dependency with the corresponding id
139 * and allows you to return different values for different modules.
140 * @default false
141 */
142 requireReturnsDefault?:
143 | boolean
144 | 'auto'
145 | 'preferred'
146 | 'namespace'
147 | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
148 /**
149 * Some modules contain dynamic `require` calls, or require modules that
150 * contain circular dependencies, which are not handled well by static
151 * imports. Including those modules as `dynamicRequireTargets` will simulate a
152 * CommonJS (NodeJS-like) environment for them with support for dynamic and
153 * circular dependencies.
154 *
155 * Note: In extreme cases, this feature may result in some paths being
156 * rendered as absolute in the final bundle. The plugin tries to avoid
157 * exposing paths from the local machine, but if you are `dynamicRequirePaths`
158 * with paths that are far away from your project's folder, that may require
159 * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
160 */
161 dynamicRequireTargets?: string | ReadonlyArray<string>
162}
163
\No newline at end of file