[英]How to publish a npm module that can be auto import in WebStorm?
I try to publish an easy module like follow: 我尝试发布一个简单的模块,如下所示:
the file list is: 文件列表是:
|--[src]
| |--[share]
| |--share.moduel.ts
| |--index.ts
|
|
|--package.json
|--index.ts
package.json 的package.json
{
"name": "my-common",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"typings": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
index.ts index.ts
export { ShareModule } from './src/share/index';
src/share.module.ts SRC / share.module.ts
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {FormsModule} from "@angular/forms";
@NgModule({
imports: [
CommonModule,
FormsModule
],
declarations: [],
exports: [CommonModule,FormsModule]
})
export class ShareModule { }
src/index.ts SRC / index.ts
export { ShareModule } from './share.module';
After I publish the npm module,and then npm install my-common
, I try to press Alt + Enter on code 'ShareModule' in order to auto organize import statement, but it doesn't show the tab " Add import statement " which works like the Angular2 HttpModulem, FormModule, etc. 在我发布npm模块,然后
npm install my-common
,我尝试在代码'ShareModule'上按Alt + Enter以自动组织import语句,但是它没有显示选项卡“ Add import statement ”像Angular2 HttpModulem,FormModule等。
So how could I make my own module that can be auto import by key Alt + Enter in WebStorm like other Angular2's official module? 那么我怎么能像其他Angular2的官方模块那样通过WebStorm中的键Alt + Enter自动导入我自己的模块呢? Are there some key point I missed?
我错过了一些关键点吗?
Finally,I find how to make it work. 最后,我找到了如何使它工作。
Step 1 create two file in your **/src/**
folder like follow: 第1步在
**/src/**
文件夹中创建两个文件,如下所示:
index.d.ts index.ts index.d.ts index.ts
Step 2 edit your index.d.ts you show export the class you want to use Alt + Enter to import in WebStrom 第2步编辑index.d.ts,显示要导出要使用的类Alt + Enter以在WebStrom中导入
for example 例如
export declare class ShareModule {
}
Step 3 edit your index.ts like follow: 第3步编辑你的index.ts如下:
export {ShareModule} from './share/share.module';
Step 4 make two file in / folder like follow 第4步在/文件夹中创建两个文件,如下所示
index.ts: index.ts:
export * from './src/index';
index.d.ts: index.d.ts:
export * from './src/index'
Finally, the files should like follow: 最后,文件应该如下:
|--[src] | |--[share] | | |--share.moduel.ts | |--index.ts | |--index.d.ts | | |--package.json |--index.ts |--index.d.ts
Now you can import your class by Alt + Enter 现在您可以通过Alt + Enter导入您的课程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.