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

前端 未结 4 1604
暗喜
暗喜 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:42

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

    My new structure is the following:

    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

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

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

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

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

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

    And I can use this import from my application:

    import {Component} from '/Component';
    

    Thank you again.

提交回复
热议问题