如何使用TypeScript将node_modules库代码嵌入到单个JS中?

时间:2017-06-05 17:54:11

标签: jquery typescript tsc

我想将我的TypeScript项目编译成包含 JQuery的单个文件,这样我的HTML中就有一个<script src="mystuff.js"></script>标记。 tsc可以这样做吗?或者我是否需要诉诸webpack或其他类似的东西?

我的tsconfig.json看起来像这样:

{
  "compilerOptions": {
    "allowJs": true,
    "declaration": false,
    "jsx": "react",
    "moduleResolution": "node",
    "module": "amd",
    "noImplicitAny": false,
    "noImplicitThis": false,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "strict": false,
    "outFile": "chooser.js",
    "preserveConstEnums": true,
    "pretty": true,
    "removeComments": true,
    "sourceMap": true,
    "sourceRoot": "./ts/",
    "target": "es2017"
  },
  "include": [
    "ts/*.ts",
    "ts/*.tsx",
    "ts/**/*.ts",
    "ts/**/*.tsx"
  ],
  "exclude": [
    "typings"
  ]
}

我唯一的TypeScript文件现在看起来像这样:

import * as $ from 'jquery';

export function getData() {
  return new Promise((resolve, reject) => {
    $.get('/salaries.csv', {
      onComplete: (result) => {
        console.log('result', result);
      }
    })
  })
}

0 个答案:

没有答案