Wei Lin
Wei Lin

Reputation: 3811

How to disable generate "exports.__esModule = true;" and "require("lib");"

e.g:

<!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"
    }
})

after cmd tsc it'll generate below 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"
    }
});

My Expected

I hope to disable generate "exports.__esModule = true;" and "require("lib");"

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

PS:

I use DefinitelyTyped to get type definite

Upvotes: 5

Views: 6809

Answers (1)

Shaun Luttin
Shaun Luttin

Reputation: 141552

Change your tsconfig.json module to es2015 and moduleResolution to node.

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

That is the recommended configuration.

The exports.__esModule and require('lib') are what happen when we transpile from an ES module to commonjs (with babel or with TypeScript).

Upvotes: 7

Related Questions