私は独自のjavascriptライブラリをandular4-cliプロジェクトで実装したいと考えています。私自身のライブラリなので、ライブラリをnpmで含めることはできません。
tsconfig.json正しく独自のjavascriptライブラリを実装する方法、角4
{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
私は
"assets/myownlib.js"
angular.cli.jsonに私は、ライブラリを使用するコンポーネントライブラリを実装:
import { Component, OnInit } from '@angular/core';
import {DataService} from './tempdatagia.service';
import {MyLib} from '../../assets/myownlib';
@Component({
selector: 'app-paho',
templateUrl: './paho.component.html',
styleUrls: ['./paho.component.css']
})
export class PahoComponent {
// Create a client instance
client: any;
constructor(private tempdata: DataService) {
this.client = new MyLib.MQTT.Client('wpsdemo.gia.rwth-aachen.de', 8080, 'Steffen');
this.onMessage();
this.onConnectionLost();
// connect the client
this.client.connect({onSuccess: this.onConnected.bind(this)});
}
.
.
.
}
をエラー 012 '../../assets/myownlib' からラインインポート{MYLIB} ;:
で
を "JSが設定されていない許可" "名前空間を見つけることができません" MYLIB"。
「資産」または「../assets」は重要ではありませんが、違いはありません。私のlibは動作しています...ちょっとした変更を加えてすでにnpmを使って実装しているもう一つのライブラリです!私の質問は、どのように一般的に自分のjsライブラリを実装する方法が大嫌いです。パスは正しいです、パスについてはエラーがありません... – Steffn
私のlibはpaho-mqttクライアントの修正です... – Steffn
コンパイル済みの.jsファイルを.tsからインポートしようとしましたか? –