Should original Typescript code be stored in the published node_module library or not?

When developing a node module in Typescript and preparing it for publishing, I have the option to publish only the transpiled (obfuscated) code contained in the /dist folder. Alternatively, I can also choose to publish the original code found in either the /src or /lib folders.

  • If I opt to publish only obfuscated code, the library will be more compact but less transparent, functioning as more of a blackbox.
  • On the other hand, if I decide to publish both obfuscated and original code, the library will be larger but users will have the ability to delve into the code, debug, study, understand it, and even view comments.

What is considered the more traditional approach in this scenario? I have come across modules that include original code as well as those that do not.

Are there established standards regarding this practice? Is a node module containing original Typescript code inherently less production ready?

Thank you.

Answer №1

Avoid embedding pre-compiled code into your module as it does not offer any advantages.

  • Users prefer a compact and fast version of your product instead of the source code that needs to be compiled by them
  • If collaborators need to work with you, they can access the original source code from the git repository

Consider updating your tsconfig file with these configurations:

{
  "compilerOptions": {
     "outDir": "./dist",          /* Specifies the directory where output will be saved */
     "declaration": true,         /* Generates '.d.ts' files */
  }
}

The outDir option ensures that all generated sources are compiled in a designated folder at the root, keeping your code organized in one place.

By enabling the declaration setting, you create "source-mapping" files which allow TypeScript users to benefit from type information while working with the compiled code.

In your Git Repo, it is recommended to only store the original source files and exclude the generated source folder by adding dist to your .gitignore file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When validation fails, all fields are highlighted in the Div containing the FormGroup

In my Angular application, I need to utilize two fields - produced date and expiry date. It is important to note that I must use <div [formGroup]...> since this component will be called within other forms. Using the form tag here is not an option. ...

Is there someone who can assist me in transforming this constructor function into a factory function using Javascript?

const createAppError = (message, status) => { return { message, status }; }; This is the equivalent code using factory functions to create an AppError with a message and status. It achieves the same result as the constructor fun ...

Steps for implementing a conditional statement to handle an empty string in HTML

I need to figure out how to display a different message if my string is empty. Can anyone help me with this? <div class="padding" id="dealBorder"> <pre id="informationDealText"><pan class="inner-pre" style="font-size: 24px; color: whi ...

Encountered an issue while attempting to integrate Nebular into my Angular application

As a newcomer to Angular, I decided to try installing Nebular using the command ng add @nebular/theme. However, I encountered an error in the process. Upon entering the command into my terminal, the following error message appeared: ? Which Nebular theme ...

JavaScript preloader failing to wait for images to load

I came across this Javascript code to enable the pre-loader on my website. However, I noticed that it disappears as soon as the page loads, instead of waiting for all images to finish loading. After some research, I found a suggestion to use window.onload ...

Tips on arranging jQuery deferred objects in order?

I am facing an issue where I need to delay every Ajax call until the previous function (hashcode.Sign()) has completed. Unfortunately, my current code does not wait for hashcode.Sign() to finish, causing problems as this function creates a new session that ...

Is there a way to individually remove a selected radio button and its corresponding label?

Having trouble removing a selected radio button and its associated label. Struggling to implement the remove function that targets the selected radio button and removes both the button and label. function removeRadioItem() { var radios = document.getElem ...

guide on incorporating Google Maps in a Vue.js application

Can anyone help me with displaying a Google Map using Vue.js? I have provided the code below, but I keep getting an error saying "maps is undefined" even though I have installed all the necessary dependencies for Google Maps. <div id="map"></div& ...

Can a Next.js website be designed exclusively for mobile devices?

In the process of creating my Next.js application, I have developed a page that is exclusively for mobile devices. My question is how can I ensure that this page is only accessible to users on mobile devices? In case someone tries to access it from a des ...

Numerous operations included in a JavaScript document

Looking to enhance my JS file by adding multiple functions, but I'm having trouble as I'm not very familiar with JavaScript. Here's what I've got so far. $(function(){ $('.incentives').hide(); $('.incentives-click&a ...

``Is there a more SEO-friendly option instead of using an iframe?

I am looking for a solution to easily share my content with other websites without the issues I currently face. Presently, I use an iframe which poses two problems: <iframe width=“540”; height=“700” frameborder=“0” src=“http://www.energi ...

Retrieve JSON and HTML in an AJAX request

I have multiple pages that heavily rely on JavaScript, particularly for sorting and filtering datasets. These pages typically display a list of intricate items, usually rendered as <li> elements with HTML content. Users can delete, edit, or add item ...

Selenium Scrolling: Improving Web Scraping Efficiency with Incomplete Data Extraction

I have been attempting to extract product data from a website that utilizes JavaScript to dynamically render HTML content. Despite using Selenium, implementing scrolling functionality to reach the end of the page, and allowing time for the page to reload, ...

Tips for modifying environment variables for development and production stages

I am looking to deploy a React app along with a Node server on Heroku. It seems that using create-react-app should allow me to determine if I'm in development or production by using process.env.NODE_ENV. However, I always seem to get "development" ev ...

The FormGroup Matrix in Angular 2+

Looking to develop an interface for creating a matrix, which requires two inputs for width and height. The matrix of inputs will vary based on these dimensions. I'm facing a challenge in making these inputs unique so they can be correctly associated ...

Is there a way to create a fading effect for background images using jQuery?

Is there a way to animate the background-image of an element with fadein and fadeout effects on hover? ...

Preserving the video's aspect ratio by limiting the width and height to a maximum of 100%

I am trying to integrate a YouTube video using their embed code in a "pop-up". However, I am facing an issue where the video does not resize to fit within the height of its parent. I want it to be constrained by the div#pop-up that contains the video. Curr ...

Issue with rendering in sandbox environment versus localhost

Here's a dilemma I'm facing - I have some HTML code on my localhost that looks like this: <div> <p>Go to: <a href="www.foobar.com">here</a></p> </div> On localhost, the output is "Go to: here" with 'he ...

Error: The layout was unable to display the template body

I've been working on a web application with express and eta, but I'm running into an issue with including partials in my templates. Despite trying to include a file partial (refer to the Docs), the compiled template doesn't seem to incorpor ...

Decorator used in identifying the superclass in Typescript

I am working with an abstract class that looks like this export abstract class Foo { public f1() { } } and I have two classes that extend the base class export class Boo extends Foo { } export class Moo extends Foo { } Recently, I created a custom ...