Home > Back-end >  is it possible to use the github url to install typescript npm dependencies
is it possible to use the github url to install typescript npm dependencies

Time:02-11

When we want a npm lib write using typescript, we should write the source code using typescript, then push the source code to github, then transfer from typescript to javascript and push javascript to npm repo. when we add dependencies, we use the transfered javascript. Is it possible to using the typescript directly in github or keep the transfered javascript in github and use it through github url? I do not want to publish everytime change the typescript source code. The npm did not supprt override or snapshot version. I have to compile the typescript to javascript and publish to npm?Any suggestion?

CodePudding user response:

How I generally do it is by having a src/ folder that contains the TypeScript files, and have a separate folder for the built/compiled JS files say lib/

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./lib"
    },
    "exclude": [
        "lib"
    ]
}

Now, in the package.json file, you can declare your main field as ./lib/index.js (or whatever your main entry file is)

You can tell NPM to ignore files by using an .npmignore file, which operates similar to a .gitignore file.

.npmignore

# Ignore all src files
src

You can use npm pack to test what NPM will pack (it will print the tarball contents).

You can even .gitignore the lib folder since it's a generated folder.

If you provide source maps, you may still want to include the original source typescript files however.

  • Related