3

I have moved my code successfully into libraries in my NX workspace. However, I have some libraries that are rather large (utilities) with a number of small functions. As such, I would like to be able to break the import into smaller modules, similar to @angular/material which has an import for each component (button, card, etc.).

I have the following structure for instance:

-utilities
    -src
        -lib
            +date-time
            +file-types
            +functions
        index.ts

If my index.ts is:

    export * from './lib/date-time/convert-hours-minutes-to-minutes';
    export * from './lib/date-time/date-time-formats';
    export * from './lib/date-time/get-date-for-end-of-week';

    export * from './lib/functions/api-log-mode';
    export * from './lib/functions/database-log-mode';
    export * from './lib/functions/delete-from-array';
    export * from './lib/functions/field-value-list';
    export * from './lib/functions/format-bytes-for-users';

    export * from './lib/file-types/json-wrapper/json-wrapper';
    export * from './lib/file-types/microsoft-excel-wrapper/excel-js-wrapper';
    export * from './lib/file-types/xml-wrapper/xml-wrapper';

I can access all the methods I want, but they are all imported in one block:

import { DateTimeFormats, ApiLogMode } from '@my-lib/utilities';

However, I would like to break these up for smaller include lines when something is using a lot of the library functions. In that case, I would like to use an import like:

import { DateTimeFormats, GetDateForEndOfWeek } from '@mylib/utilities/date-time';

In each of my folders under the lib (date-time, functions, etc.) I have removed the index.ts from the ./lib directory, and tried to use both an index.d.ts and index.ts in each folder, without any luck.

date-time/index.ts (or index.d.ts)
    export * from './lib/date-time/convert-hours-minutes-to-minutes';
    export * from './lib/date-time/date-time-formats';
    export * from './lib/date-time/get-date-for-end-of-week';

file-types/index.ts (or index.d.ts)
    export * from './json-wrapper/json-wrapper';
    export * from './microsoft-excel-wrapper/excel-js-wrapper';
    export * from './xml-wrapper/xml-wrapper';

This still does not allow me to import as I would like. I know I could split this into even more libraries in the NX workspace, but I want to version my larger library for more generic use across our projects, so that a large 'utilities' library (1.8.x) would be included in our applications, and maintained independently.

Steven Scott
  • 10,234
  • 9
  • 69
  • 117

0 Answers0