Giter VIP home page Giter VIP logo

tsbunch's Introduction

TSBunch Logo

npmnpm

📦 TSBunch

A VERY simple bundler for TypeScript files that doesn't transpile them to JS (Multiple .ts -> Single .ts)

Introduction

There are plenty of TypeScript bundlers out there but none that don't also transpile TypeScript into regular JS. This bundler seeks to rectify that by providing a very simple way to concatenate multiple TypeScript modules into one TypeScript file.

The magic behind this bundler is in utilizing TypeScript's namespace feature rather than using the traditional bundler loading pattern.

The impetus behind this was to allow TypeScript projects composed of multiple modules to be uploaded to CodinGame (which only accepts single flat files) either by hand or by using the CodinGame Sync App WITHOUT transpiling those TypeScript files to JavaScript in the process.

Usage

Installing:

$ npm install --save-dev tsbunch

tsbunch(entryFilePath, [outputFilePath], [declarationsFile(s)])

  • entryFilePath: String file path of the bundle entry file
  • outputFilePath: (Optional) Name of output file, will default to out.ts
  • declarationsFile(s): (Optional) Single or array of string file paths to files which will placed at the top of the output file 'outside' of the bundle.

Create a file with the following in it:

const tsbunch = require('tsbunch');
tsbunch('path/to/entryFile.ts', 'path/to/outputFile.ts', 'path/to/declarationsFile.d.ts');

Finally run that file with:

$ node file.js

Caveats

This bundler is using string matching rather than AST's so doesn't fully support the import/export spec:

Supports:
  • import defaultExport from "module-name";
  • import * as name from "module-name";
  • import { export1 } from "module-name";
  • import { export1 as alias1 } from "module-name";
  • import { export1 , export2 } from "module-name";
  • import { export1 , export2 as alias2 , [...] } from "module-name";
  • import defaultExport, { export1 [ , [...] ] } from "module-name";
  • import defaultExport, * as name from "module-name";
  • export let name1, name2, …, nameN; // also var, const
  • export let name1 = …, name2 = …, …, nameN; // also var, const
  • export function functionName(){...}
  • export class ClassName {...}
  • export const { name1, name2: bar } = o;
  • export default expression;
Has Partial Support

The following examples will have their function/class names changed. It's recommended to save them as constants and then export the constants rather than to directly default export them:

  • export default function (…) { … } // also function*
  • export default function name1(…) { … } // also function*
  • export default class { … }
  • export default class name1{ … }
Will Not Work:
  • import { foo , bar } from "module-name/path/to/specific/un-exported/file";
  • import "module-name";
  • var promise = import("module-name");
  • export { name1, name2, …, nameN };
  • export { name1 as default, … };
  • export { variable1 as name1, variable2 as name2, …, nameN };
  • export * from …; // does not set the default export
  • export * as name1 from …;
  • export { name1, name2, …, nameN } from …;
  • export { import1 as name1, import2 as name2, …, nameN } from …;
  • export { default } from …;

TSBunch will also not resolve any circular dependencies. If compilation is taking unusually long, it's recommended to check for these.

Scripts

  • npm run build: compiles TS files
  • npm run test: runs all tests
  • npm run testWatch: runs all tests in watch mode

Todo/Future Improvements

  • Use tsconfig.json for file import

Notes

Credits

Available for Hire

I'm available for freelance, contracts, and consulting both remotely and in the Hudson Valley, NY (USA) area. Some more about me and what I can do for you.

Feel free to drop me a message at:

hi [a+] zweisolutions {●} com

License

MIT

tsbunch's People

Contributors

chinanf-boy avatar dependabot[bot] avatar hg-pyun avatar ranyitz avatar rkrupinski avatar ronami avatar roymiloh avatar zweihander-main avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.