我用打字稿创建了一个自定义组件,并将其发布到npm。 但是,当我尝试通过npm install在我的项目中使用它时,它将在浏览器控制台中引发错误
Failed to load my-component.template.html
但是如果我直接使用模板,它可以代替templateUrl
my-component.component.ts
import {Component} from "@angular/core";
@Component({
selector:'my-component',
templateUrl:'./my-component.template.html',
})
export class MyComponentComponent{
constructor(){}
}
我的package.json
{
"name": "my-component",
"version": "1.0.2",
"description": "",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"prepublishOnly": "npm run compile",
"compile": "npm run clean && tsc -p . && npm run copy:html",
"watch": "tsc -w -p .",
"clean": "rm -rf dist",
"copy:html": "cpx \"src/*.html\" \"dist/src\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@angular/animations": "^6.0.3",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"typescript": "^2.6.1",
"copy": "^0.3.0",
"cpx": "^1.5.0"
},
"files": [
"dist/index.js",
"dist/index.d.ts",
"dist/src"
]
}
我正在编写一个脚本,以在包中包含.html my-component source code