
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
gulp-ts-package
Advanced tools
Renames modules as a package in a compiled typescript bundle (system or amd).
Renames modules as a package in a compiled typescript bundle (system or amd).
npm install --save-dev gulp-ts-package
gulpfile.js
let gulp = require("gulp");
let ts = require('gulp-typescript');
let tsPackage = require('gulp-ts-package').default;
gulp.task("build", function () {
let tsProject = ts.createProject({ module: "amd", outFile: "bundle.amd.js" });
return gulp.src("src/**/*.ts")
.pipe(tsProject())
// Assuming your main module is at: src/index.ts
.pipe(tsPackage({ name: "my-library", mainModule: "index" }))
.pipe(gulp.dest("lib/"));
]);
});
Enabling minify will change the name of non-root modules.
The new name will be numbered after the package name. Example: "myPackage/1".
gulpfile.js
let gulp = require("gulp");
let ts = require('gulp-typescript');
let tsPackage = require('gulp-ts-package').default;
gulp.task("build", function () {
let tsProject = ts.createProject({ module: "amd", outFile: "bundle.amd.js" });
return gulp.src("src/**/*.ts")
.pipe(tsProject())
// Assuming your main module is at: src/index.ts
.pipe(tsPackage({
name: "my-library",
mainModule: "index",
minify: {
enabled: true,
// Optional:
ignoredModules: ["ModuleC"]
}
}))
.pipe(gulp.dest("lib/"));
]);
});
Use the "outFile" parameter in the tsconfig.
https://www.typescriptlang.org/docs/handbook/compiler-options.html
If you are building a typescript library, you can:
The original bundle file registers the modules by relative names, For example: "index".
Problems:
import * as myLib from "my-lib";) will not work in the browser (out of the box).
Notice that developers who uses bundling tools (like webpack), can avoid those issues by consuming and bundling the commonjs format of your library. The downside is performance.
I personally try to devide my application to libraries when possible.
That way I can enjoy smaller scope, faster builds and test runs, modularity, reusabilty, and more...
All while keeping the maintanence relatively low (for example, short gulpfile.js).
For this approach, this library is very helpful.
You can see the source code of the files used in this example. The files are in the repository.
... // Some helper function might be here.
System.register("folder2/B", ["folder1/A"], function (exports_1, context_1) { ...
System.register("folder1/A", ["folder2/B"], function (exports_2, context_2) { ...
System.register("index", ["folder1/A", "folder2/B"], function (exports_3, context_3) { ...
... // Some helper function might be here.
System.register("my-library/folder2/B", ["my-library/folder1/A"], function (exports_1, context_1) { ...
System.register("my-library/folder1/A", ["my-library/folder2/B"], function (exports_2, context_2) { ...
System.register("my-library", ["my-library/folder1/A", "my-library/folder2/B"], function (exports_3, context_3) { ...
... // Some helper function might be here.
define("folder2/B", ["require", "exports", "folder1/A"], function (require, exports, A_1) { ...
define("folder1/A", ["require", "exports", "folder2/B"], function (require, exports, B_1) { ...
define("index", ["require", "exports", "folder1/A", "folder2/B"], function (require, exports, A_2, B_2) { ...
... // Some helper function might be here.
define("my-library/folder2/B", ["require", "exports", "my-library/folder1/A"], function (require, exports, A_1) { ...
define("my-library/folder1/A", ["require", "exports", "my-library/folder2/B"], function (require, exports, B_1) { ...
define("my-library", ["require", "exports", "my-library/folder1/A", "my-library/folder2/B"], function (require, exports, A_2, B_2) { ...
FAQs
Renames modules as a package in a compiled typescript bundle (system or amd).
We found that gulp-ts-package demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.