TypeStrong / ts-loader

TypeScript loader for webpack
https://johnnyreilly.com/ts-loader-goes-webpack-5
MIT License
3.44k stars 429 forks source link

preserve namespaces #1565

Closed TobiasKoller closed 1 year ago

TobiasKoller commented 1 year ago

Expected Behaviour

when using

export namespace My.NP{
  export function MyFunction(){}
}

MyFunction should be accessable through My.NP.MyFunction()

Actual Behaviour

The First part of the namespace (here My) gets replaced with a random character. Depending on the configuration it's preserving the namespace but its not accessable through My.NP.MyFunction..

Steps to Reproduce the Problem

create a typescript-file and use a namespace with a dot-separator

Location of a Minimal Repository that Demonstrates the Issue.

TobiasKoller commented 1 year ago

Ok I finally found a solution after search for hours. when putting this in the webpack-config it adds it to the window-variable.

...
 output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "dist"),
    globalObject: "this",
    library: "My",
    libraryTarget: "window",
  },

and then I had to remove the "My" from my Namespace because its already the key in the "library"-setting.

export namespace NP{
  export function MyFunction(){}
}

after that I'm able to access it on my website through My.NP.MyFunction()