簡體   English   中英

TypeScript捆綁不適用於外部模塊

[英]TypeScript bundling not working for External Modules

我有一個示例TypeScript代碼,並且正在嘗試使用Typescript編譯器(tsc) 捆綁多個ts / tsx文件。

這是代碼:

文件:ISample.ts

    class ISample{
        constructor(public value:string){
        }
    }
    export = ISample;

文件:Sample.ts

    import ISample = require('./ISample');

    class SampleImpl{
        value: ISample;
        constructor(sample:number){
            this.value = new ISample(sample+'');
        }
    }

檔案:tsconfig.json

    {
        "compilerOptions": {
            "module": "amd",
            "noImplicitAny": true,
            "removeComments": true,
            "preserveConstEnums": true,
            "jsx": "react",
            "outFile": "./dist/bundle.js",
            "target": "es3",
            "listFiles": true,
            "sourceMap": false
        },
        "files": [
            "./src/Sample.ts",
            "./src/ISample.ts"
        ]
    }

當我運行命令時:

    tsc

bundle.js已生成,但完全空白。

觀察結果:

  1. 當我將代碼移到內部模塊時,不會發生此問題

  2. 當我省略import / require語句並為ISample類使用聲明時,也不會發生此問題,但是在那種情況下bundle.js不包含ISample類的代碼

任何想法為什么會這樣?

暫時不支持此功能: 建議:多文件外部模塊

有一套解決方法,例如使用模塊編譯TypeScript並將其捆綁到一個文件中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM