Jam*_*ley 11 javascript npm angular
我正在考虑使用这个Yeoman生成器作为一个迷你项目的入门者,该项目包含我可以发布的一些可重用的表单组件.生成器构建模块以及配置使用的示例组件,指令,管道和服务(您可以在此处查看生成器的模板文件).
然后npm link,我曾经允许我在我的Angular应用程序中安装生成的项目,看起来工作正常,如下面从项目node_modules目录中所示;
Run Code Online (Sandbox Code Playgroud)
根据这些项目或其他内容,我错过了什么让这个工作?谢谢!
编辑:sample.*.d.ts文件(安装后默认为)
{
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "ES5",
"emitDecoratorMetadata": true, <-- Checked to ensure this was true
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true,
"outDir": "./dist"
},
"files": [
"typings/index.d.ts",
"index.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
Run Code Online (Sandbox Code Playgroud)
编辑2
所以我尝试将dist目录(my-test-library/dist)符号链接到根目录node_modules并从那里导入模块,它工作正常.
npm link,只导入dist目录(在根目录)?import { SampleModule } from 'my-test-library/dist';不起作用?您是否尝试在代码上运行 watch(例如“npm run watch”)?这会给出更好的错误消息。
假设这是您的index.ts文件或与此类似的文件(https://github.com/jvandemo/generator-angular2-library/blob/master/generators/app/templates/index.ts)我猜测是您的模块未正确导出,或者导出之间存在一些循环依赖关系。首先,尝试更改 index.ts 中的以下四行:
export * from './src/sample.component';
export * from './src/sample.directive';
export * from './src/sample.pipe';
export * from './src/sample.service';
Run Code Online (Sandbox Code Playgroud)
到
export {SampleComponent} from "./src/sample.component";
export {SampleDirective} from "./src/sample.directive";
export {SamplePipe} from "./src/sample.pipe";
export {SampleService} from "./src/sample.service";
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,请尝试更改导出的顺序。如果仍然没有成功,请尝试在某个地方共享整个文件夹。谢谢,
| 归档时间: |
|
| 查看次数: |
743 次 |
| 最近记录: |