7

I'm working on a typescript project that uses import/export style syntax for modules. I want to compile all the typescript files into a single file. Here is how my tsconfig.json looks like,

{
  "compilerOptions": {
    "module": "UMD",
    "noImplicitAny": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "target": "ES5",
    "lib": [
      "es2016",
      "dom"
    ],
    "outFile": "dist/beetl.js"
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

When I run the tsc command I'm getting the below error,

error TS6082: Only 'amd' and 'system' modules are supported alongside --outFile.

I don't want to go with AMD or System and I want UMD, How can I achieve that?

VJAI
  • 32,167
  • 23
  • 102
  • 164
  • I've to stick with webpack to achieve this. Hopefully tsc will provide this in future. – VJAI Jan 30 '17 at 10:42
  • with webpack we still end up with multiple declaration files which is problematic – Ozymandias Apr 29 '19 at 06:32
  • I found [this gist](https://gist.github.com/jayphelps/51bafb4505558736fdba0aaf8bfe69d3) that has basically every output format you will eventually need. – Machado May 10 '20 at 08:13

1 Answers1

3

If you use the grunt-typescript npm module and grunt to transpile, UMD will work with a single file output. Below is an example configuration block for your gruntfile.js:

typescript: {
        options: {
            module: 'umd', 
            target: 'es5',
            rootDir: 'src',
            sourceMap: true,
            declaration: true,
            removeComments: true
        },
        base: {
            src: ['src/**/*.ts', "!**/*.d.ts"],
            dest: 'dist/gen/OUT_FILE.js',
        }
    }