0

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",
      }
    }

1 Answer 1

1

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

Why

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

Sign up to request clarification or add additional context in comments.

1 Comment

Can I use globs in the webpack.config.js. I have an app folder with controllers, directives, services and filters folders for my angularjs code. So I have different typescript files that I need to compile if I use entry: './src/app/**/*.ts', i get an error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.