Reputation: 4984
I'm trying to create a build script using just npm without grunt or gulp.
Most things are working apart from concatenating typescript.
I can compile single typescript files but I have a number of separate files I need to concatenate and then compile.
I'm using the concat-cli mobule but it doesn't seem to concatenate files and just outputs the first file in the folder.
What the best way to concatenate typescript files.
{
"name": "starter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"scss": "node-sass --output-style compressed -o src/assets/css src/assets/sass/main.scss",
"compile:ts": "tsc --outDir ./src/assets/js/ --module commonjs ./src/app/**/*.ts",
"concat:ts": "concat-cli --files src/app/**/*.ts --output dist/js/output.ts",
"serve": "browser-sync start --server --files 'src/assets/css/, src/assets/js/*.js, **/*.html, !node_modules/**/*.html'",
"watch:css": "onchange 'src/assets/sass/*.scss' -- npm run scss",
"watch:js": "onchange 'src/app/**/*.js' -- npm run jshint",
"watch:ts": "onchange 'src/app/**/*.ts' -- npm run concat:ts",
"watch:all": "npm-run-all -p serve watch:css watch:js watch:images",
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.13.0",
"concat": "0.0.1-security",
"concat-cli": "^4.0.0",
"node-sass": "^3.8.0",
"onchange": "^2.5.0",
"typescript": "^1.8.10",
}
}
Upvotes: 0
Views: 1779
Reputation: 275799
What the best way to concatenate typescript files.
Use modules and use a module loader like webpack. QuickStart : https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html
Blindly concatenating JS file without using a module system will be rife with ReferenceError: Variable not defined
and TypeError : undefined is ....
. There are also other maintainability reasons. More : https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html
Upvotes: 1