Languages
[Edit]
EN

JavaScript - join js files using tsc

9 points
Created by:
Paluskitten
356

In this short article we would like to show how to join pure JavaScript files into single js file with tsc command.

Note: you can read this article too, to see how to compile *.ts file int single js file.

 

Simple steps:

1. prepare configuration for TypeScript compiler that will join our *.js files togather

There are avaialble two modules that let join files togather amd or system - in the below example we use amd one.

tsconfig.json file example:

{
	"version": "4.0.3",
	"compilerOptions": {
		"strict": true,
		"target": "es5",
		"module": "amd",  /* <----------------------- requred  */
		"composite": true,
		"declaration": true,
		"allowJs": true,  /* <----------------------- requred  */
		"sourceMap": true,  /* <--------------------- only for easier development  */
		"rootDir": "resources/",
		"outFile": "resources/merged.js"  /* <------- requred  */
	},
	"files": [
		"resources/lib/js/jquery/jquery.min.js",
		"resources/lib/js/sweetalert2/sweetalert2.js",
		"resources/lib/js/leaflet/leaflet.js",
		"resources/js/common.js",
		"resources/js/popper.js"
	]
}

Where:

  • files property contains list of all files that should be joined - should be served in order we want keep.

2. run compiler

It is necessary to run tsc command from same directory, where is located tsconfig.json file.

Command example:

tsc

or

tsc -p path/to/tsconfig.json

Note: as result we should see src/main/webapp/resources/merged.js file with combined js files.

Alternative titles

  1. JavaScript - join js files into one using tsc
  2. JavaScript - combine js files into one using tsc
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join