/// /// /// /// /// import * as rollup from 'rollup'; import { Plugin } from 'rollup'; import * as postcss from 'postcss'; import cssnano from 'cssnano'; import { RawSourceMap } from 'source-map-js'; /** File resolved by `@import` resolver */ interface ImportFile { /** Absolute path to file */ from: string; /** File source */ source: Uint8Array; } /** `@import` resolver */ declare type ImportResolve = (url: string, basedir: string, extensions: string[]) => Promise; /** `@import` handler options */ interface ImportOptions { /** * Provide custom resolver for imports * in place of the default one */ resolve?: ImportResolve; /** * Aliases for import paths. * Overrides the global `alias` option. * - ex.: `{"foo":"bar"}` */ alias?: Record; /** * Import files ending with these extensions. * Overrides the global `extensions` option. * @default [".css", ".pcss", ".postcss", ".sss"] */ extensions?: string[]; } /** File resolved by URL resolver */ interface UrlFile { /** Absolute path to file */ from: string; /** File source */ source: Uint8Array; /** Original query extracted from the input path */ urlQuery?: string; } /** URL resolver */ declare type UrlResolve = (inputUrl: string, basedir: string) => Promise; /** URL handler options */ interface UrlOptions { /** * Inline files instead of copying * @default true for `inject` mode, otherwise false */ inline?: boolean; /** * Public Path for URLs in CSS files * @default "./" */ publicPath?: string; /** * Directory path for outputted CSS assets, * which is not included into resulting URL * @default "." */ assetDir?: string; /** * Enable/disable name generation with hash for outputted CSS assets * or provide your own placeholder with the following blocks: * - `[extname]`: The file extension of the asset including a leading dot, e.g. `.png`. * - `[ext]`: The file extension without a leading dot, e.g. `png`. * - `[hash(:)]`: A hash based on the name and content of the asset (with optional length). * - `[name]`: The file name of the asset excluding any extension. * * Forward slashes / can be used to place files in sub-directories. * @default "assets/[name]-[hash][extname]" ("assets/[name][extname]" if false) */ hash?: boolean | string; /** * Provide custom resolver for URLs * in place of the default one */ resolve?: UrlResolve; /** * Aliases for URL paths. * Overrides the global `alias` option. * - ex.: `{"foo":"bar"}` */ alias?: Record; } /** Options for [CSS Modules](https://github.com/css-modules/css-modules) */ interface ModulesOptions { /** * Default mode for classes * @default "local" */ mode?: "local" | "global" | "pure"; /** Fail on wrong order of composition */ failOnWrongOrder?: boolean; /** Export global classes */ exportGlobals?: boolean; /** * Placeholder or function for scoped name generation. * Allowed blocks for placeholder: * - `[dir]`: The directory name of the asset. * - `[name]`: The file name of the asset excluding any extension. * - `[local]`: The original value of the selector. * - `[hash(:)]`: A hash based on the name and content of the asset (with optional length). * @default "[name]_[local]__[hash:8]" */ generateScopedName?: string | ((name: string, file: string, css: string) => string); } /** * Loader * @param T type of loader's options */ interface Loader> { /** Name */ name: string; /** * Test to control if file should be processed. * Also used for plugin's supported files test. */ test?: RegExp | ((file: string) => boolean); /** Skip testing, always process the file */ alwaysProcess?: boolean; /** Function for processing */ process: (this: LoaderContext, payload: Payload) => Promise | Payload; } /** * Loader's context * @param T type of loader's options */ interface LoaderContext> { /** * Loader's options * @default {} */ readonly options: T; /** @see {@link Options.sourceMap} */ readonly sourceMap: false | ({ inline: boolean; } & SourceMapOptions); /** Resource path */ readonly id: string; /** Files to watch */ readonly deps: Set; /** Assets to emit */ readonly assets: Map; /** [Plugin's context](https://rollupjs.org/guide/en#plugin-context) */ readonly plugin: rollup.PluginContext; /** [Function for emitting a warning](https://rollupjs.org/guide/en/#thiswarnwarning-string--rollupwarning-position-number---column-number-line-number---void) */ readonly warn: rollup.PluginContext["warn"]; } /** Extracted data */ interface Extracted { /** Source file path */ id: string; /** CSS */ css: string; /** Sourcemap */ map?: string; } /** Loader's payload */ interface Payload { /** File content */ code: string; /** Sourcemap */ map?: string; /** Extracted data */ extracted?: Extracted; } /** Options for sourcemaps */ interface SourceMapOptions { /** * Include sources content * @default true */ content?: boolean; /** Function for transforming resulting sourcemap */ transform?: (map: RawSourceMap, name?: string) => void; } /** Options for Sass loader */ interface SASSLoaderOptions extends Record, sass.PublicOptions { /** Force Sass implementation */ impl?: string; /** Forcefully enable/disable sync mode */ sync?: boolean; } /** Options for Less loader */ interface LESSLoaderOptions extends Record, less.PublicOptions { } /** Options for Stylus loader */ interface StylusLoaderOptions extends Record, stylus.PublicOptions { } /** Options for PostCSS config loader */ interface PostCSSConfigLoaderOptions { /** Path to PostCSS config file directory */ path?: string; /** * Context object passed to PostCSS config file * @default {} */ ctx?: Record; } /** CSS data for extraction */ interface ExtractedData { /** CSS */ css: string; /** Sourcemap */ map?: string; /** Output name for CSS */ name: string; } /** Options for CSS injection */ interface InjectOptions { /** * Insert `