我正在使用webpack和typescript为javascript和typescript(用于扩展)构建库。我想让类扩展其他npm库的(导出抽象类的)抽象类,但是当我运行编译的代码时,它会引发错误。
类扩展未定义的值不是构造函数或null
程序似乎在运行时尝试将已编译(js)类中的抽象类加载。
我的代码:
webpack配置
const development = process.env.dev === "true" ? true : false;
console.log(development);
const path = require("path");
module.exports = {
mode: development ? "development" : "production",
target: 'node',
entry:{
index:"./src/index.ts"
},
output:{
libraryTarget: 'commonjs2',
filename: 'index.js',
path: path.resolve(__dirname, "dist")
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
//exclude: /node_modules/,
},
]
},
resolve: {
extensions: ['.ts', '.js', '.json']
},
plugins: [
],
externals: [
]
};
tsconfig
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es2017",
"esModuleInterop": true,
"declaration": true,
"baseUrl": ".",
"paths": {
"@src/*":["src/*"]
},
"lib": ["dom","es2017"]
},
"include": [
"src/*",
"src/**/*"
]
}
Compiler.ts
import { Controller } from "npmLibraryName"; //Controller is abstract class
class Compiler extends Controller {
init(){}
}
export default Compiler;