我有一个用打字机写的图书馆。我可以用
tsc
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"es5",
"dom",
"es2017"
],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"listEmittedFiles": true
},
"exclude": [
"./dist",
"./test",
"./bin"
],
"include": [
"./lib"
]
}
但是当另一个项目试图从链接的npm包中使用这个库时,它无法使用
webpack
和
ts-loader
错误:Typescript没有为/library/path/to发出输出/文件.ts
注:
webpack尝试从链接的目标加载它,而不是从
node_modules
因为它与npm相连
.
项目的网页包配置使用库如下。
module.exports = (entry, dist) => Object.assign({
entry,
mode: "production",
output: {
filename: "index.js",
path: dist,
},
resolve: {
extensions: [".js", ".ts"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
stats: 'verbose'
});
tsconfig.json文件该项目的使用库
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"es5",
"dom",
"es2017"
],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": [
"./dist"
],
"include": [
"./index.ts"
]
}
import {Ctor, Injector} from "./injector";
import {ERROR_CODES, PuzzleError} from "./errors";
import {Route} from "./server";
export interface ApiEvents {}
export interface ApiConfig {
route: Route;
subApis?: Array<Ctor<Api>>;
}
interface ApiBase {
}
export function PuzzleApi<T>(config: ApiConfig) {
return Injector.decorate((constructor: () => void) => {
console.log(`Registering Api: ${constructor.name}`);
}, config);
}
export class Api implements ApiBase {
config: ApiConfig;
constructor() {
const config = (this.constructor as any).config as ApiConfig;
if (!config) {
throw new PuzzleError(ERROR_CODES.CLASS_IS_NOT_DECORATED, this.constructor.name);
} else {
this.config = config;
}
}
}
我找不到它不为那个项目输出的任何原因。我可以毫无问题地传送图书馆。有人能帮我吗?