UNPKG

4.7 kBTypeScriptView Raw
1import { AcceptedPlugin, Transformer } from "postcss";
2
3export = atImport;
4
5/**
6 * 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`
7 * 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
8 * to look at.
9 *
10 * **Notes:**
11 *
12 * - **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
13 * can expect**.
14 * - 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.
15 * - 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).
16 * If this behavior is not what you want, look at `skipDuplicates` option
17 * - **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
18 * hood).
19 * - Imports which are not modified (by `options.filter` or because they are remote imports) are moved to the top of the output.
20 * - **This plugin attempts to follow the CSS `@import` spec**; `@import` statements must precede all other statements (besides `@charset`).
21 */
22declare function atImport(options?: atImport.AtImportOptions): Transformer;
23
24declare namespace atImport {
25 interface AtImportOptions {
26 /**
27 * 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
28 * argument and should return a boolean.
29 *
30 * @default () => true
31 */
32 filter?: (path: string) => boolean;
33
34 /**
35 * Define the root where to resolve path (eg: place where `node_modules` are). Should not be used that much.
36 *
37 * _Note: nested @import will additionally benefit of the relative dirname of imported files._
38 *
39 * Default: `process.cwd()` or dirname of [the postcss from](https://github.com/postcss/postcss#node-source)
40 */
41 root?: string | undefined;
42
43 /**
44 * A string or an array of paths in where to look for files.
45 */
46 path?: string | string[] | undefined;
47
48 /**
49 * An array of plugins to be applied on each imported files.
50 */
51 plugins?: AcceptedPlugin[] | undefined;
52
53 /**
54 * 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
55 * 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
56 * [resolve](https://github.com/substack/node-resolve) for this.
57 */
58 resolve?:
59 | ((
60 id: string,
61 basedir: string,
62 importOptions: AtImportOptions,
63 ) => string | string[] | PromiseLike<string | string[]>)
64 | undefined;
65
66 /**
67 * You can overwrite the default loading way by setting this option. This function gets `(filename, importOptions)` arguments and returns content or promised content.
68 */
69 load?: ((filename: string, importOptions: AtImportOptions) => string | Promise<string>) | undefined;
70
71 /**
72 * 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
73 * want, just set this option to false to disable it.
74 *
75 * @default true
76 */
77 skipDuplicates?: boolean | undefined;
78
79 /**
80 * An array of folder names to add to Node's resolver. Values will be appended to the default resolve directories: `["node_modules", "web_modules"]`.
81 *
82 * 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.
83 */
84 addModulesDirectories?: string[] | undefined;
85 }
86}
87
\No newline at end of file