UNPKG

3.48 kBTypeScriptView Raw
1import { ImportedClientSettings } from './config';
2export interface KnownImportOptions {
3 chunkName?: string;
4 webpackChunkName?: string;
5 webpackPreload?: boolean;
6 webpackPrefetch?: boolean;
7}
8declare type ImportOptions = KnownImportOptions | Record<string, string | boolean>;
9/**
10 * @name ImportedConfiguration
11 * react-imported-component configuration
12 * __TO BE USED AT `imported.js`__
13 * @see {@link https://github.com/theKashey/react-imported-component#-imported-js}
14 */
15export interface ImportedConfiguration {
16 /**
17 * tests folder during scanning process. Can be used to optimize scanning process.
18 * @default ignores `node_modules` and `.*` directories
19 * @returns boolean flag
20 * - true, dive in
21 * - false, stop here
22 */
23 testFolder?: (targetName: string) => boolean;
24 /**
25 * tests if this file should scanned by `imported-component`.
26 * Keep in mind that you might consider removing (unit)test files from the scan
27 * @param fileName - source file name
28 * @returns {Boolean} true - if should, false - is should not
29 * @example
30 * // hides node modules
31 * testFile(filename) { return !filename.test(/node_modules/); }
32 */
33 testFile?: (fileName: string) => boolean;
34 /**
35 * tests if a given import should be visible to a `imported-component`
36 * This method is equivalent to `client-side` magic comment
37 * @param {String} targetFileName - import target
38 * @param {String} sourceFileName - source filename
39 * @returns {Boolean} false if import should be ignored by the `imported-components`
40 * @see {@link https://github.com/theKashey/react-imported-component/#server-side-auto-import}
41 * @example
42 * //a.js -> source
43 * import('./b.js) -> target
44 * @example
45 * testImport(filename, source, config) {
46 * return !(
47 * // no mjs please
48 * filename.indexOf('.mjs')===-1
49 * // no webpack-ignore please (don't do it)
50 * config.webpackIgnore
51 * )
52 * }
53 */
54 testImport?: (targetFileName: string, sourceFileName: string) => boolean;
55 /**
56 * marks import with prefetch comment (if possible)
57 * @param {String} targetFile
58 * @param {String} sourceFile
59 * @param sourceConfiguration
60 */
61 shouldPrefetch?: (targetFile: string, sourceFile: string, sourceConfiguration: ImportOptions) => boolean;
62 /**
63 * marks import with preload comment (if possible)
64 * @param {String} targetFile
65 * @param {String} sourceFile
66 * @param sourceConfiguration
67 */
68 shouldPreload?: (targetFile: string, sourceFile: string, sourceConfiguration: ImportOptions) => boolean;
69 /**
70 * adds custom chunkname to a import (if possible)
71 * @param {String} targetFile
72 * @param {String} sourceFile
73 * @param {String|undefined} givenChunkName
74 * @returns
75 * {string} - a new chunk name
76 * {undefined} - keep as is
77 * {null} - keep as is (will remove in the future)
78 */
79 chunkName?: (targetFile: string, sourceFile: string, importOptions: ImportOptions) => string | null | undefined;
80 /**
81 * clientside configuration properties to be passed into `setConfiguration`
82 */
83 configuration?: Partial<ImportedClientSettings>;
84}
85/**
86 * provides react-imported-component configuration
87 * @param {ImportedConfiguration} config
88 */
89export declare const configure: (config: ImportedConfiguration) => ImportedConfiguration;
90export {};