Leveraging ts-loader alongside strip-loader in Webpack

I am currently facing an issue with strip-loader in my Typescript project that is built with Webpack.

The ts-loader statement in my project is as follows:

{ test: /\.ts$/, loader: 'babel-loader?presets[]=es2015!ts-loader' }

Everything seems to be working fine with this configuration. However, I have a lot of console logging using Angular's $log service, and I want to remove lines like:

this.$log.log ("Some message here");

To achieve this, I made an update to my Webpack file:

{ test: /\.ts$/, loader: 'babel-loader?presets[]=es2015!strip-loader?strip[]=this.log!ts-loader' }

My thought process was to generate ES6 with TS, strip out lines starting with this.$log, and then transpile it to ES5 with Babel. However, despite trying different patterns in strip-loader like strip[]=this, it doesn't seem to have any effect on the code.

Can someone please point out what I might be doing wrong?

Thank you, Jeff

Answer №1

In your current regex pattern, you have included $ which signifies the end of a string. Make sure to escape it properly:

{ test: /\.ts\$/, loader: 'babel-loader?presets[]=es2015!strip-loader?strip[]=this.\\$log.log!ts-loader' }

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

"Implement a selection feature in ng-grid using a 'select all' checkbox without cluttering the grid with a checkbox for every

Is there a way to create a grid with the first column empty, except for the header which must have a "Select All" checkbox? With the current code, all columns are filled with checkboxes, but when I set "showSelectionCheckbox:false", the "Select All" check ...

React fails to display image on the server

One issue I'm facing with my React project on the server is that some images are not being displayed. Click here to view image description The console error message reads: ASGimagen.png:1 GET https://[url of my server]/autodiagnostico/cuadroanimado ...

Is it necessary for a writable stream in NodeJS to wait for the drain event before writing again automatically?

Below is the code I am working with: const { Writable } = require('stream') let writable = new Writable({ highWaterMark: 10 }) writable._write = (chunk, encoding, cb) => { process.stdout.write(chunk) } function writeData(iterations, writ ...

Tips for displaying or concealing table rows with form fields on a php site by utilizing jquery/ajax and a drop-down menu selection

Is there a way to hide or unhide table rows with form fields in a php website based on a dropdown selection using jquery/ajax? The current script I have only hides the field, leaving blank rows. How can I also hide the respective table rows? Thank you for ...

When using Webpack and Typescript together with the watch feature, an error with code TS2554 may occur only during

Software in use: webpack 4.8.3 typescript 2.8.3 ts-loader 4.3.0 Configuration for Webpack: rules: [ { test: /\.ts(x?)$/, exclude: /node_modules/, use: ['ng-annotate-loader', 'ts-loader'] }, . ...

Adding LocalStorage functionality to buttons in order to switch colors can be done by storing the

I've run into an issue trying to incorporate LocalStorage with the buttons that change colors as themes in JavaScript. I'm new to coding and eager to add this feature to my personal blog. $(document).ready(function () { $(".header--theme-button ...

The React form is only transmitting a single property from the state instead of the complete state

My current challenge involves sending form data from my react client to my nodejs server. The issue I am facing is that only the last property of the state gets sent to the server upon form submission. This problem seems to be occurring on the client side, ...

Ways to dynamically retrieve a key value pair in JavaScript and React

I am currently working with a spreadsheet element where the cell values are stored in an object structure like this: localCells = {A1: {input: 'hi', value: 'world'}, A2: {input:'how', value:'you?'}} The object is q ...

What is the correct way to integrate a HTML/CSS/JS theme into a Vue project effectively?

As a newcomer, I recently acquired a bootstrap theme that comes with HTML, CSS, and JavaScript files. My goal now is to integrate this theme into Vue in order to make it fully functional. The challenge I am facing is how to successfully incorporate the the ...

What is preventing absolute paths from functioning properly in TurboRepo?

After setting up a fresh project on the most recent version of TurboRepo, I ventured into the 'apps' directory and established a new Vite project using the 'react-swc-ts' template. Making tweaks to the 'tsconfig.json' file wit ...

Dynamic JavaScript Line Graph

I am facing a challenge with a small function in my application that needs to display real-time data on a webpage. I have been exploring different Javascript examples, such as the Flot example "real-time updates" and the Highcharts example "spline updating ...

NativeScript has just faced a critical issue: an Uncaught ReferenceError has occurred stating that the variable __UI_USE_EXTERNAL_RENDERER__ is not

While working on iOS on my Mac, I encountered an unexpected error. ***** Fatal JavaScript exception - application has been terminated. ***** NativeScript encountered a fatal error: Uncaught ReferenceError: __UI_USE_EXTERNAL_RENDERER__ is not defined at (f ...

"Express API POST request functions successfully on Postman, however encounters difficulties when used with AJAX

My goal is to send an AJAX request from JavaScript to my ExpressJS Rest API. Unfortunately, the POST call is not working in JavaScript. Interestingly, when I use Postman, the same JSON data with the same headers works perfectly. Here is the error I&apos ...

There is a problem with the Angular document because it is not

I am looking to optimize my Angular app for production by running the following command: npm run build:ssr SSR stands for server-side rendering. However, after completing the build process, I encounter an error within my header components. The error mes ...

creating an HTML table from JSON data using a specific key

In this json file, I am looking to create separate tables based on the IDs provided. For example, ID: "50" should be displayed in one table, while ID: "57" should be shown in another table within the same context. { "version": "5.2", "user_type": ...

live PHP recording of data moving between tables

As a beginner, I am working on a project to organize groups of people on the screen using PHP code. I have managed to list Distribution Lists, Member Lists, and People, but I lack experience in this area. Can anyone provide some guidance on how to proceed? ...

Issue encountered while working with PostgreSQL and Sequelize when using the array_append function

I'm encountering issues with the following code snippet let user = req.user.id; await MyTable.update( {'interested': Sequelize.fn('array_append', Sequelize.col('interested'), user)}, {'where ...

When a React component's function is passed in as a parameter, it fails to be acknowledged as a function

I've been struggling to pass a function as a parameter to a component, but it doesn't recognize the function I'm passing in as a function. Here's an important snippet from the page: const Home = () => { const nav = useNavigate() co ...

Add information in the JSON structure

I am trying to display some JSON data in a div, but the current code is not working. Can anyone suggest where I should make changes? <div class="risktable"> </div> $.ajax({ contentType:'application/json', data: {"sp ...

Tips for combining values from two inputs to an angular ng-model in AngularJS

I am working with an angular application and I am trying to figure out how to combine values from multiple inputs into one ng-model. Here is an example of my current input: <input type="text" class="form-control input-md" name="type" ng-model="flat.f ...