如何在不带"dist"的情况下在NPM上发布TypeScript模块?在进口? [英] How to publish TypeScript modules on NPM without "dist" in import?

查看:90
本文介绍了如何在不带"dist"的情况下在NPM上发布TypeScript模块?在进口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NPM上发布一个打字稿库,但是发布后我找不到好的"路径.

I'm trying to publish a typescript library on NPM but I can't to have a "good" path after publishing.

关于这一点,我遵循了一些指南,但没有找到解决方法.

I follow several guide on this point but I'm not found a solution.

问题:因此,请考虑以下结构:

The problem: So, consider the following structure:

dist
 |- Alls files generated after tsc build
lib
 |- All TS files of library (source)
CHANGELOG.md
LICENSE
package.json
README.md
tsconfig.json

发布后,例如在Angular应用程序中,我将输入:

After publishing, for instance in an Angular application, I shall type:

import {Component} from '<library name>/dist/Component';

我的问题:我如何配置项目导入,使其具有来自'<库名称>/Component'的而不是来自'< library name>/dist/Component'>请?

My question: How can I configure project import to have from '<library name>/Component' instead from '<library name>/dist/Component' please?

谢谢

推荐答案

关于@ joe-clay的建议,我找到了一个解决方案.

On suggestions of @joe-clay, I found a solution.

我的新结构如下:

dist
 |- Alls files generated after tsc build
 |- package.json
 |- LICENSE
 |- README.md
src
 |- All TS files of library (source)
CHANGELOG.md
LICENSE
README.md
tsconfig.json

dist 目录在README.md和NPM软件包页面的LICENSE文件中发布在NPM上.

The dist directory is published on NPM with README.md and LICENSE file for NPM package page.

根目录是Github上具有README.md,LICENSE和CHANGELOG.md的入口,用于Github上的开发过程.

The root directory is the entry point on Github with README.md, LICENSE and CHANGELOG.md for development process on Github.

tsconfig.json 放在根目录上,因为如果位于 dist 目录中,我找不到能正确构建的解决方案.

tsconfig.json is placed on the root because I don't find a solution to have correct build if located inside dist directory.

package.json 中,我添加了脚本"build":"cd ../&&tsc" ,以便能够在 dist 目录内执行 npm run build .

In package.json, I add the script "build": "cd ../ && tsc" in order to be able to execute npm run build inside dist directory.

采用这种结构,图书馆开发和NPM发布可以正常工作.

With this structure, library development and NPM publishing works fine.

我可以从我的应用程序中使用此导入:

And I can use this import from my application:

import {Component} from '<library name>/Component';

再次感谢您.

这篇关于如何在不带"dist"的情况下在NPM上发布TypeScript模块?在进口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆