Skip to content

What is the workflow to distribute a library ? #4545

Closed
@aboeglin

Description

@aboeglin

Hi everyone,

I spent two days trying to figure out this module-internal-external-namespace-import-export thing, and I have to say, it's counter intuitive, and not very easy to use.

So, let's pretend that we have a little module that should be consumed by different projects. The module is composed of two classes A and B in the two files A.ts and B.ts. We want to bundle it in a file called library.js along with a type definitions in library.d.ts. I tried two main things so far :

  • internal module library, so that my files would look like this :
//A.ts
module library {
  class A {
  }
}

B.ts
module library {
  class B {
  }
}

Then I would use the --out option, which should be called --outFile but that my compiler as of version 1.5.3 doesn't know of. I end up with a .js file, which doesn't contain a module.exports = library. Which makes it fail to load in node. And the library.d.ts generated doesn't contain export = library, which leads to the compile error TS2306 library.d.ts is not a module. Of course, I played around, tried to create a file library.ts that would import or export things trying to compile it and hope it would generate what was needed.

I also tried to play with external modules, but this can't be the way to go as it seems impossible to generate a single file from it.

So, is there anywhere, a guide or manual that clearly explains how to bundle code ? A sort of step by step process. Looking at references online it seems a lot of people are after that, and a lot of people struggle with it. It can't be that hard can it ? People get confused with internal modules, external modules, namespaces, are internal modules actually gone ?

So what is "the way" of packaging a library that can be consumed by a browser and node ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions