Languages
[Edit]
EN

JavaScript - join js files using tsc

9 points
Created by:
Kate_C
19800

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.

Native Advertising
50 000 ad impressions - 449$
šŸš€
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

ā¤ļøšŸ’» šŸ™‚

Join