Webpack can generate separate compiled files in addition to the bundle

Currently, I am utilizing the webpack loader ts-loader to convert typescript source files into a javascript bundle. My goal now is to not only save the compiled javascript bundle but also the individual compiled javascript files. While I have experience in creating basic webpack plugins, I am unsure of how to approach this task. Specifically, I am unsure of which webpack events to listen for and where to access the necessary data. Any suggestions or guidance would be greatly appreciated!

Answer №1

After my initial comment, it became apparent that using webpack compiled individual files could lead to issues. There is a risk of encountering a

Uncaught ReferenceError: __webpack_require__ is not defined
error.

It would be advisable to either develop your own loader or inquire with the ts-loader team about incorporating an option to preserve the transpiled source.

Alternatively, I have created a loader that saves the typescript compiled files as separate entities.

You can implement this loader as a second loader or a post-loader:

As a second loader:

module: {
    loaders: [{
      test: /\.ts?$/,
      loaders: ['scatter-loader', 'ts-loader']
    }]
}

Or as a post-loader:

module: {
    loaders: [{
      test: /\.ts?$/,
      loaders: ['ts-loader']
    }],
    postLoader: [{
      test: /\.ts?$/,
      loaders: ['scatter-loader']
    }]
}

Note: The development of scatter-loader is currently ongoing.

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

Analyzing registration details stored in an array against user login credentials

With two buttons available - one for sign up and the other for log in, my goal is to gather input form values from the sign-up section into an array. Following this, I aim to compare the user input from the sign-up with that of the log-in, informing the us ...

Transforming mp4 or Avi files into m3u8 using only node js

I'm currently exploring ways to convert a mp4 or .avi file to .m3u8 using pure node js (specifically, a Firebase Cloud Function). Does anyone have any suggestions? Thank you, but I've already attempted the following: const ffmpegInstaller = requ ...

What are the steps for importing and utilizing data from a JSON object?

After successfully importing data from a JSON file that was an Array, I've encountered a new challenge - my variable is now an object. My goal is to push all the questions from the object into an array and then display them on the HTML document. You c ...

What is the best way to incorporate one Div within another Div using JavaScript?

I have a single main div with an id, and I am looking to insert 4 additional child divs inside it. Each of these child divs will then contain 5 more divs each. The code snippet that I currently have is as follows: $( document ).ready(function() { for( ...

Maintain HTML formatting when page is refreshed

I am new to HTML and JavaScript, and I'm trying to modify the JavaScript code below so that when I reload the page, it retains the most recent active tab instead of defaulting back to the first tab. Currently, if I click on the second tab for "Paris" ...

Problem encountered with imaskJS in handling the formatting of data with forward slashes

After conducting tests on the frontend of the imask website at , it has been verified that utilizing a forward slash for date formatting results in the exclusion of the final digit of the date. Various attempts were made, including: IMask( field, ...

Is it possible to update the text within a button when hovering over it in Angular?

https://i.sstatic.net/ZhNeM.png https://i.sstatic.net/kb670.png I'm looking to update the text displayed inside a button when hovering over it, similar to the examples in these images. I have already implemented the active state, but now I just need ...

Adding values to an array with the click of a submit button in React JS

I have a unique challenge with creating a form that includes custom inputs. const Input = (props) => { return ( <div> <label className={classes.label}>{props.label} <input className={classes.input} {... ...

What is the best way to activate a post function using a hyperlink?

I'm struggling to figure out how to call my post function using a link within my navbar. The issue is that I'm working with links in the navbar code, and not sure how to integrate calling the post function with them. Below is the code for my pos ...

When a fetch request is called inside a map function in React, the return

I attempted to retrieve a map array through fetch resolves so that each element inside favoriteCards would return a value and assign it to the test variable useEffect(() => { const test = favoriteCards.map((card) => { accuWeatherApi.getCurrentW ...

Implementing updates to a website from a database without the need for a page refresh

I am eager to delve into the world of AJAX and have identified a seemingly straightforward challenge that I believe will serve as an informative learning experience. Imagine a scenario where users are continuously adding new entries to a database table. ...

How do I specify a unique directory for pages in Next.js that is not within the src or root folders?

I'm currently facing an issue when trying to set a custom directory in Next JS. Although the default setup dictates that the pages directory should be located at the root or within the src directory, this arrangement doesn't fit my requirements ...

The callback function in WordPress is executed twice

I've been working on a custom WordPress plugin that includes a form for sending data to a database. However, I've encountered an issue where every time I click the submit button, the callback function runs twice, resulting in duplicate entries in ...

Creating a sidebar navigation in HTML and CSS to easily navigate to specific sections on a webpage

Here's a visual representation of my question I'm interested in creating a feature where scrolling will display dots indicating the current position on the page, allowing users to click on them to navigate to specific sections. How can I achieve ...

The process of efficiently uploading a batch of images to Firebase storage while also obtaining all the respective

I have been using firebase storage to upload images and save their respective URLs in the firebase database. However, I recently encountered an issue with my code. In firebase v8, everything was working fine, but after updating to version 9, the following ...

The error message "ch.match is not a function" appeared in the Javascript code

Here are two functions that I need help with: //Function A var ltrToNato = function(ch) { var x = ch; var nato = ('{"A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India" ...

Use ajax calls instead of using the bind() function in Drupal for better performance

Currently, I have an AJAX call that is bound to the window popstate event. While it works fine, the issue arises when parsing arguments from the querystring. The problem lies in the fact that the ajax call gets bound to the window on page load, causing the ...

MaterialUI makeStyles in NextJS causes custom css to revert back when the page is refreshed

Currently, I am working on a NextJS website with some unique styling applied through MaterialUI's makeStyles. Initially, everything looks perfect but then all the custom styling is reset on the second load. It seems to be related to the route, as it o ...

How should I integrate my JS authentication function in Rshiny to enable the app to utilize the outcome?

Currently, I have an Rshiny application set to be published on the server but in order to ensure that a specific user has access, we require an API authentication token. The process of authentication is handled within JS tags outside of the application, wh ...

What steps do I need to take for Typescript to acknowledge my unique global filter function?

I recently developed a unique Vue.js filter to properly format markdown syntax. While the filter functions as intended, I've encountered an issue with TypeScript (specifically in PhpStorm) not recognizing the 'markdown' filter within my comp ...