网页 综合 更新时间 2026-11-13 17:18:37

Configuration Options | Rollup

自动蜘蛛 rollupjs.org 正文约 6000 字
Command Line Interface
Running Rollup in a Browser
Frequently Asked Questions
Migrating to Rollup 4
Configuration Options
Either a function that takes an id and returns true (external) or false (not external), or an Array of module IDs, or regular expressions to match module IDs, that should remain external to the bundle. Can also be just a single ID or regular expression. The matched IDs should be either:
Note that if you want to filter out package imports, e.g. import {rollup} from 'rollup', via a /node_modules/ regular expression, you need something like @rollup/plugin-node-resolve to resolve the imports to node_modules first.
When given as a command line argument, it should be a comma-separated list of IDs:
When providing a function, it is called with three parameters (id, parent, isResolved) that can give you more fine-grained control:
When creating an iife or umd bundle, you will need to provide global variable names to replace your external imports via the output.globals option.
Note that source phase imports (import source x from 'y') are required to be external. Rollup will raise an error if a source phase import resolves to a module that is not external.
If a relative import, i.e. starting with ./ or ../, is marked as "external", rollup will internally resolve the id to an absolute file system location so that different imports of the external module can be merged. When the resulting bundle is written, the import will again be converted to a relative import. Example:
The conversion back to a relative import is done as if output.file or output.dir were in the same location as the entry point or the common base directory of all entry points if there is more than one.
The bundle's entry point(s) (e.g. your main.js or app.js or index.js). If you provide an array of entry points or an object mapping names to entry points, they will be bundled to separate output chunks. Unless the output.file option is used, generated chunk names will follow the output.entryFileNames option. When using the object form, the [name] portion of the file name will be the name of the object property while for the array form, it will be the file name of the entry point.
Note that it is possible when using the object form to put entry points into different sub-folders by adding a / to the name. The following will generate at least two entry chunks with the names entry-a.js and entry-b/index.js, i.e. the file index.js is placed in the folder entry-b:
If you want to convert a set of files to another format while maintaining the file structure and export signatures, the recommended way—instead of using output.preserveModules that may tree-shake exports as well as emit virtual files created by plugins—is to turn every file into an entry point. You can do so dynamically e.g. via the glob package:
The option can be omitted if some plugin emits at least one chunk (using this.emitFile) by the end of the buildStart hook.
When using the command line interface, multiple inputs can be provided by using the option multiple times. When provided as the first options, it is equivalent to not prefix them with --input:
Chunks can be named by adding an = to the provided value:
File names containing spaces can be specified by using quotes:
Allows Rollup to process JSX syntax to either preserve or transform it depending on the jsx.mode. If set to false, an error will be thrown if JSX syntax is encountered. You may also choose a preset that will set all options together:
This will determine how JSX is processed:
"preserve": Will keep JSX syntax in the output.
"classic": This will perform a JSX transformation as it is needed by older React versions or other frameworks like for instance Preact. As an example, here is how you would configure jsx for Preact:
This would perform the following transformation:
"automatic": This will perform a JSX transformation using the new JSX transform introduced with React 17. In this mode, Rollup will try to import helpers from jsx.jsxImportSource to transform JSX. As there are certain edge cases, this mode may still fall back to using the classic transformations when using the key property together with spread attributes. To this end, you can still specify jsx.importSource, jsx.factory, and jsx.fragment to configure classic mode.
The function Rollup uses to create JSX elements in "classic" mode or as a fallback in "automatic" mode. This is usually React.createElement for React or h for other frameworks. In "preserve" mode, this will ensure that the factory is in scope if jsx.importSource is specified, or otherwise that a global variable of the same name would not be overridden by local variables. Only in "preserve" mode it is possible to set this value to null, in which case Rollup will not take care to keep any particular factory function in scope.
If the value contains a "." like React.createElement and an jsx.importSource is specified, Rollup will assume that the left part, e.g. React, refers to the default export of the jsx.importSource. Otherwise, Rollup assumes it is a named export.
The element function Rollup uses to create JSX fragments. This is usually React.Fragment for React or Fragment for other frameworks. In "preserve" mode, this will ensure that the fragment is in scope if jsx.importSource is specified, or otherwise that a global variable of the same name would not be overridden by local variables. Only in "preserve" mode it is possible to set this value to null, in which case Rollup will not take care to keep any particular fragment function in scope.
If the value contains a "." like React.Fragment and an jsx.importSource is specified, Rollup will assume that the left part, e.g. React, refers to the default export of the jsx.importSource. Otherwise, Rollup assumes it is a named export.
Where to import the element factory function and/or the fragment element from. If left to null, Rollup will assume that jsx.factory and jsx.fragment refer to global variables and makes sure they are n
访问原文 返回搜索 https://rollupjs.org/configuration-options/
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。