webpack-contrib/expose-loader

doc: Please add an example how to export functions/classes from my own lib

MikeMitterer opened this issue · 2 comments

I want to expose some of my TS-classes to 'window' but I have no idea how to automate this process with expose-loader...

At the moment I'm doing it manually like so: (exports.ts)
(just in case someone else has the same problem...)

import { Name as NameToExport } from "./address/Name";
import {
    addValues as addValuesToExport,
    sayMyName as sayMyNameToExport,
} from "./index";

declare global {
    namespace MyLib {
        export type Name = NameToExport;
        export const Name: typeof NameToExport;

        export const addValues: typeof addValuesToExport;
        export const sayMyName: typeof sayMyNameToExport;
    }
}

(window as any).MyLib = {
    Name: NameToExport,
    addValues: addValuesToExport,
    sayMyName: sayMyNameToExport,
};

I'm using webpack 4 and TS 3

Is not implemented yes, will be part of the next release

Fixed, but you need to specify custom custom-type-definitions-to-a-third-party-library in your application manually , here examples https://www.detroitlabs.com/blog/2018/02/28/adding-custom-type-definitions-to-a-third-party-library/