Can I set up a watch for changes in ng build within Visual Studio's Pre Build events?

I have successfully set up an angular-cli based project in Visual Studio 2017 by following the steps outlined in this link:

Within my project's Pre-Build events, I have the following commands:

echo "cd $(SolutionDir)" &&^
cd "$(SolutionDir)" &&^
echo "Building Project" &&^
ng build &&^
echo 'copy files' &&^

When I Build or Rebuild the project in Visual Studio, everything works correctly. The bundle files are generated in the output directory as specified in angular-cli.json.

However, I am looking for a way to watch for changes using ng build from within Visual Studio. I attempted to add ng build --watch in the Pre-Build events, but it caused the Build process to hang indefinitely. Although the correct bundle files were being generated in the output directory, the Build process never completed in Visual Studio 2017.

As a temporary solution, I am currently running ng build --watch in a separate command window, which monitors and rebuilds the project as expected when changes are made to TypeScript, HTML, or CSS files. However, I would prefer to integrate this functionality natively within Visual Studio 2017.

Please note: While I have included "compileOnSave": true in my tsconfig.json, it does not provide the same capabilities as ng build. Thank you.

Answer №1

In case anyone is in need of a solution, here is what I have included in the Pre-build event for Visual Studio:

powershell start-process "cmd " """/k ng build --watch"""

This command will launch a new cmd window, initiate the ng build process, and continuously monitor for any changes. However, it is important to close the cmd window after completing your debugging session. Failure to do so will result in a new cmd window opening each time you press F5.

Answer №2

It seems that the issue with running it as part of a build event in Visual Studio is due to Visual Studio waiting for the script to complete before continuing with the build. Since the script is continuously monitoring for changes during the Angular CLI build process, it never truly "finishes."

I am considering automating this process for myself.

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

Combining object IDs with identical values to create a new array in JavaScript

i have an array of objects that are a join between the transaction, product, and user tables. I want to merge IDs with the same value so that it can display two different sets of data in one object. Here's my data let test = [ { Transac ...

Pair items with identical names within an array

I am faced with a task where I need to merge filter elements with equal titles in order to avoid repetition. The goal is to display all inner elements together under one title if they have the same name. For example, if two filters both named FILTER-AB ha ...

Does the Array Splice method always remove an item from the end?

I'm having trouble with deleting an item from an array using Array.splice. It seems to always delete the item from the end instead of where I want it to be removed. I'm working with Vue.js and dynamically adding items to an array, but when I try ...

Arrange and display similar objects together

I have a list of items in a listView that need to be visually grouped based on their class, displayed within boxes. For example, I have 5 items with the following classes: <div class="1"></div> <div class="1"></div> <div class= ...

Getting the Firebase Project Name or ID from a Cloud Function is a simple task that involves using

While working with Cloud Functions, I need to retrieve the project name from one of my Javascript server files. The project name is stored in .firebaserc file, but I am not sure if this file is accessible on the server side. Is there a way to achieve somet ...

Determining the completion of loading in Android WebView

I am seeking to understand how to accurately determine when a WebView has finished loading in its entirety. To clarify what is meant by "completely": All redirects have been processed The entire page is visibly displayed, with no additional elements lef ...

Is it possible to enable selection functionality for WebGL text geometry once it has been integrated into the viewer's scene?

Upon adding a text geometry object to the viewer, I realized that I am unable to select it with the mouse as I can with other objects in the viewer. How can I make this text selectable? I have not attempted any solutions yet, as the documentation does not ...

"Despite establishing a successful connection with the client, NodeJs Postgres + AWS Lambda still experiences timeouts

Lambda Function: const customer = new Customer({ user: 'postgres', host: 'rds_host', database: 'dbname', password: 'db_password', port: 5432 }); exports.handler = async (event, context, callback) ...

"HTML glitches in Onsen 2: A Dynamic Dilemma

During runtime, my app context is dynamically generated. In Onsen 1.3, I utilized the following function to create and compile the HTML: $scope.generateFrom = function (div) { var el = div; var html = HTMLGenerator.getHTML(); el.in ...

Incorporating a new Autodesk Forge extension

Hey there! I'm currently working on integrating a forge extension into my viewer, but I seem to have missed something along the way. I've been following this helpful guide: Here's the code snippet that I'm using: <body> < ...

Transform the user input fields into an array format and store it in the Local Storage for

I am working on converting multiple input fields into an array so that I can store them in Local Storage. Using a jQuery script, each input field is scanned and assigned a name based on its ID. HTML: <input class="field" type="checkbox" id="field-01" ...

Is there a way to retrieve a button element from a pug template?

Why can't I use a button in index.js from a pug template? Here is the code in my pug template: doctype html html head meta(charset='UTF-8') meta(http-equiv='X-UA-Compatible' content='IE=edge') meta(name=& ...

Detect the "@" character through keyUp for the implementation of @mentions feature

I am currently working on implementing an @mention feature using Vue and Vanilla JS, but I am facing issues with targeting the "@" character specifically. Within my template: <trix-editor ref="trix" @keyup="listenForUser" ></trix-editor& ...

Display custom modals in React that showcase content for a brief moment before the page refreshes

I recently developed a custom modal in React. When the Open button is clicked, showModal is set to true and the modal display changes to block. Conversely, clicking the Close button sets the display to none. However, I noticed a bug where upon refreshing ...

What is the best way to integrate a React component into an Angular project?

Struggling with integrating a React component into an Angular project and unable to make it work. I have a JavaScript file containing the React component that I want to use in Angular. Here's an example: React file... import React from "react"; c ...

Tips for accessing and retrieving stored values within an array using JavaScript

I am trying to display stored values in an array one by one within an HTML table. The issue I'm facing is that currently, all values are being fetched at once. Can someone assist me in reading the values one by one? <script> var time=""; ...

Retrieve dynamic data for Pivot in Devexpress AngularJS

I am currently working on an AngularJS web app where I am implementing a Pivot using devexpress, specifically utilizing the Field Chooser. You can find the example code here: In the provided example, static data is used. However, I need to fetch data dyna ...

Establish a callback function for opening a fresh window using JavaScript

Is there a simple method to assign a "callback" function to a new window opened in javascript? My goal is to execute a function from the parent window in the new window, but I want the parent to be able to specify the name of this specific function (withou ...

"Implementing JavaScript Validation for Textboxes: A Step-by-Step Guide

I need some help with restricting the input of a textbox within a gridview to only 'X' or 'O'. I am not very familiar with javascript, so any guidance on how to accomplish this would be greatly appreciated. It's worth noting that t ...

How to use getServerSideProps in Next.js

In my current scenario, I find myself within a folder in the pages directory, specifically in a file named [id].jsx. My goal is to make getServerSideProps return just the name of the page, for example /page/id123 should return id123. import Link from &a ...