UNPKG

3.1 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 if this file should scanned by `imported-component`
18 * @param fileName - source file name
19 * @returns {Boolean} true - if should, false - is should not
20 * @example
21 * // hides node modules
22 * testFile(filename) { return !filename.test(/node_modules/); }
23 */
24 testFile?: (fileName: string) => boolean;
25 /**
26 * tests if a given import should be visible to a `imported-component`
27 * This method is equivalent to `client-side` magic comment
28 * @param {String} targetFileName - import target
29 * @param {String} sourceFileName - source filename
30 * @returns {Boolean} false if import should be ignored by the `imported-components`
31 * @see {@link https://github.com/theKashey/react-imported-component/#server-side-auto-import}
32 * @example
33 * //a.js -> source
34 * import('./b.js) -> target
35 * @example
36 * testImport(filename, source, config) {
37 * return !(
38 * // no mjs please
39 * filename.indexOf('.mjs')===-1
40 * // no webpack-ignore please (don't do it)
41 * config.webpackIgnore
42 * )
43 * }
44 */
45 testImport?: (targetFileName: string, sourceFileName: string) => boolean;
46 /**
47 * marks import with prefetch comment (if possible)
48 * @param {String} targetFile
49 * @param {String} sourceFile
50 * @param sourceConfiguration
51 */
52 shouldPrefetch?: (targetFile: string, sourceFile: string, sourceConfiguration: ImportOptions) => boolean;
53 /**
54 * marks import with preload comment (if possible)
55 * @param {String} targetFile
56 * @param {String} sourceFile
57 * @param sourceConfiguration
58 */
59 shouldPreload?: (targetFile: string, sourceFile: string, sourceConfiguration: ImportOptions) => boolean;
60 /**
61 * adds custom chunkname to a import (if possible)
62 * @param {String} targetFile
63 * @param {String} sourceFile
64 * @param {String|undefined} givenChunkName
65 * @returns
66 * {string} - a new chunk name
67 * {undefined} - keep as is
68 * {null} - keep as is (will remove in the future)
69 */
70 chunkName?: (targetFile: string, sourceFile: string, importOptions: ImportOptions) => string | null | undefined;
71 /**
72 * clientside configuration properties to be passed into `setConfiguration`
73 */
74 configuration?: Partial<ImportedClientSettings>;
75}
76/**
77 * provides react-imported-component configuration
78 * @param {ImportedConfiguration} config
79 */
80export declare const configure: (config: ImportedConfiguration) => ImportedConfiguration;
81export {};