如何禁用生成“ exports .__ esModule = true;”和“ require(” lib“);”

时间:2019-06-08 00:28:57

标签: typescript

例如:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        {{ message }}
    </div>

    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js'></script>
    <script src="app.js"></script>
</body>
</html>

app.ts:

import { Vue } from "vue/types/vue";

let vue = new Vue({
    el:"#app",
    data:{
        text:"hello world"
    }
})

在cmd tsc之后,它将在js下面生成

"use strict";
exports.__esModule = true;
var vue_1 = require("vue/types/vue");
var vue = new vue_1.Vue({
    el: "#app",
    data: {
        text: "hello world"
    }
});

我的期望

我希望禁用生成“ exports .__ esModule = true;”和“ require(” lib“);”

var vue = new Vue({
    el: "#app",
    data: {
        text: "hello world"
    }
});

PS:

我使用DefinitelyTyped来获得确定的类型

1 个答案:

答案 0 :(得分:1)

将您的 tsconfig.json module更改为es2015,将moduleResolution更改为node

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node"
  }
}

那是recommended configuration

transpile from an ES module to commonjs(使用babel或TypeScript)会发生exports.__esModulerequire('lib')