EN
JavaScript - join js files using tsc
9 points
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:
xxxxxxxxxx
1
{
2
"version": "4.0.3",
3
"compilerOptions": {
4
"strict": true,
5
"target": "es5",
6
"module": "amd", /* <----------------------- requred */
7
"composite": true,
8
"declaration": true,
9
"allowJs": true, /* <----------------------- requred */
10
"sourceMap": true, /* <--------------------- only for easier development */
11
"rootDir": "resources/",
12
"outFile": "resources/merged.js" /* <------- requred */
13
},
14
"files": [
15
"resources/lib/js/jquery/jquery.min.js",
16
"resources/lib/js/sweetalert2/sweetalert2.js",
17
"resources/lib/js/leaflet/leaflet.js",
18
"resources/js/common.js",
19
"resources/js/popper.js"
20
]
21
}
22
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:
xxxxxxxxxx
1
tsc
or
xxxxxxxxxx
1
tsc -p path/to/tsconfig.json
Note: as result we should see
src/main/webapp/resources/merged.js
file with combined js files.