Compiling typescript with UMD option into a single file

大城市里の小女人 提交于 2020-01-14 09:38:07

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/41755444/compiling-typescript-with-umd-option-into-a-single-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!