无法导入我的自定义打字稿 npm 包

Can not import my custom typescript npm package

我制作了一个 typescript npm 包,就像这样:

Core.ts

class Core{
    constructor(){}
    //some functions
}
export = Core;

Core.d.ts

declare class Core {
   constructor(){}
   //some functions
}
export = Core;

Package.json

{
  "name": "@company/Core",
  "main": "dist/Core.js",
  "typings": "dist/Core" //.d.ts
  //etc
}

我用 webpack 和 ts-loader 制作了这个模块。

在我的项目中,index.ts

import Core = require('@company/Core');
let core = new Core(); //Error, Core is not a function

我曾尝试以某种形式更改 exportimport,但没有成功。我是不是漏掉了一些知识?

最后,我自己解决了我的问题。我在 webpack 配置文件中添加了两个属性,然后重新编译它并运行良好。

webpack.config.js

module.exports = {
    output: {
        libraryTarget: 'commonjs'
    }
    //etc
}