1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export interface RollupCommonJSOptions {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | include?: string | RegExp | readonly (string | RegExp)[]
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | exclude?: string | RegExp | readonly (string | RegExp)[]
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | extensions?: ReadonlyArray<string>
|
34 | |
35 |
|
36 |
|
37 |
|
38 | ignoreGlobal?: boolean
|
39 | |
40 |
|
41 |
|
42 |
|
43 | sourceMap?: boolean
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | ignoreDynamicRequires?: boolean
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | transformMixedEsModules?: boolean
|
68 | |
69 |
|
70 |
|
71 |
|
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 |