UNPKG

4.94 kBTypeScriptView Raw
1// Type definitions for postcss-import 14.0
2// Project: https://github.com/postcss/postcss-import#readme
3// Definitions by: Remco Haszing <https://github.com/remcohaszing>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6import { AcceptedPlugin, Transformer } from 'postcss';
7
8export = atImport;
9
10/**
11 * This plugin can consume local files, node modules or web_modules. To resolve path of an `@import` rule, it can look into root directory (by default `process.cwd()`), `web_modules`, `node_modules`
12 * or local modules. _When importing a module, it will look for `index.css` or file referenced in `package.json` in the `style` or `main` fields._ You can also provide manually multiples paths where
13 * to look at.
14 *
15 * **Notes:**
16 *
17 * - **This plugin should probably be used as the first plugin of your list. This way, other plugins will work on the AST as if there were only a single file to process, and will probably work as you
18 * can expect**.
19 * - This plugin works great with [postcss-url](https://github.com/postcss/postcss-url) plugin, which will allow you to adjust assets `url()` (or even inline them) after inlining imported files.
20 * - In order to optimize output, **this plugin will only import a file once** on a given scope (root, media query…). Tests are made from the path & the content of imported files (using a hash table).
21 * If this behavior is not what you want, look at `skipDuplicates` option
22 * - **If you are looking for glob, or sass like imports (prefixed partials)**, please look at [postcss-easy-import](https://github.com/trysound/postcss-easy-import) (which use this plugin under the
23 * hood).
24 * - Imports which are not modified (by `options.filter` or because they are remote imports) are moved to the top of the output.
25 * - **This plugin attempts to follow the CSS `@import` spec**; `@import` statements must precede all other statements (besides `@charset`).
26 */
27declare function atImport(options?: atImport.AtImportOptions): Transformer;
28
29declare namespace atImport {
30 interface AtImportOptions {
31 /**
32 * Only transform imports for which the test function returns `true`. Imports for which the test function returns `false` will be left as is. The function gets the path to import as an
33 * argument and should return a boolean.
34 *
35 * @default () => true
36 */
37 filter?: (path: string) => boolean;
38
39 /**
40 * Define the root where to resolve path (eg: place where `node_modules` are). Should not be used that much.
41 *
42 * _Note: nested @import will additionally benefit of the relative dirname of imported files._
43 *
44 * Default: `process.cwd()` or dirname of [the postcss from](https://github.com/postcss/postcss#node-source)
45 */
46 root?: string | undefined;
47
48 /**
49 * A string or an array of paths in where to look for files.
50 */
51 path?: string | string[] | undefined;
52
53 /**
54 * An array of plugins to be applied on each imported files.
55 */
56 plugins?: AcceptedPlugin[] | undefined;
57
58 /**
59 * You can provide a custom path resolver with this option. This function gets `(id, basedir, importOptions)` arguments and should return a path, an array of paths or a promise resolving to
60 * the path(s). If you do not return an absolute path, your path will be resolved to an absolute path using the default resolver. You can use
61 * [resolve](https://github.com/substack/node-resolve) for this.
62 */
63 resolve?:
64 | ((
65 id: string,
66 basedir: string,
67 importOptions: AtImportOptions,
68 ) => string | string[] | PromiseLike<string | string[]>)
69 | undefined;
70
71 /**
72 * You can overwrite the default loading way by setting this option. This function gets `(filename, importOptions)` arguments and returns content or promised content.
73 */
74 load?: ((filename: string, importOptions: AtImportOptions) => string | Promise<string>) | undefined;
75
76 /**
77 * By default, similar files (based on the same content) are being skipped. It's to optimize output and skip similar files like `normalize.css` for example. If this behavior is not what you
78 * want, just set this option to false to disable it.
79 *
80 * @default true
81 */
82 skipDuplicates?: boolean | undefined;
83
84 /**
85 * An array of folder names to add to Node's resolver. Values will be appended to the default resolve directories: `["node_modules", "web_modules"]`.
86 *
87 * This option is only for adding additional directories to default resolver. If you provide your own resolver via the `resolve` configuration option above, then this value will be ignored.
88 */
89 addModulesDirectories?: string[] | undefined;
90 }
91}
92
\No newline at end of file