How to publish TypeScript modules on NPM without “dist” in import?

前端 未结 4 1607
暗喜
暗喜 2021-02-19 02:59

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 solut

4条回答
  •  无人及你
    2021-02-19 03:35

    The vast majority of module bundling tools follow Node's module resolution rules, which effectively say that if you specify a path after a library name, it will resolve that relative to the module's node_modules folder. You can't override this, and it's almost certainly never going to change for backward compatibility reasons.

    Without asking for your users to configure their module bundler, the only way this can be achieved is by publishing your package with the directory structure matching that which you wish to expose to your users. You could use scripts/NPM hooks (e.g. prepublish and postpublish) to automate this.

提交回复
热议问题