Angular CLI in ASP.NET core with hot module replacement - asp.net-core

We want to use Angular CLI for our projects within ASP.NET core. As output we choose wwwroot instead of dist. The default ng serve enables hot module replacement automatically. But now we need to have hot module replacement with kestrel and iis integration. We decided not to use the AspNet core Javascriptservices because we want to use Angular CLI as the default.
Does anyone know how to do enable hot module replacement with Angular CLI and the ASP.NET core standard hostring with staticfiles within the wwwroot?

I am able to run angular cli with these steps.
Make sure you have latest typescript install on your system.
Create asp.net core angular template project in Visual Studio 2017.
Now update all the npm packages with npm-check-updates
Install npm packages with
npm install
Install angular/cli globally
npm install #angular/cli#latest -g
Install angular/cli locally
npm install #angular/cli#latest --save-dev
Create an angular project outside your main project on any temp location with this command:
ng new hello-world
Now, go to project directory and copy .angular-cli.json file into the root of your main dot net core project.
Then you have to edit this part of the file:
"root" : "src" change to "root" : "ClientApp"
Everythings was done!
Now, go to your component directory of your project:
cd ClientApp/app/components
and make your component in component directory in terminal:
ng g c MyComponent --module='app.module.browser.ts'

The answer is that we have to accept on the local host environment to have 2 local host servers running together when developing. Ng serve with webpack dev server for the client code (angular app) and iis express with kestrel for web api or MVC... This way you can use hot module replacement with ng serve.

Related

Why angular.json is removed from Angular 14?

I have created a new angular project with the ng new command.
Angular CLI: 14.2.0
Node: 16.14.0
Package Manager: npm 8.3.1
OS: darwin arm64
Angular: 14.1.3
It has created a project which includes angular.json and the commands ng serve, and ng build were working. I just learned that angular.json is no longer used it was managed by angular CLI in the latest angular 14 versions. So, I tried to delete angular.json from my root project. But now the ng commands were not working.
The ng serve command gives the error: This command is unavailable when running the Angular CLI outside a workspace.
What does it mean? How can I fix this issue? Is it necessary to keep angular.json for workspace configuration? How can I serve my project without angular.json?

Is it okay to use NPM packages along Composer in Laravel PHP project

Is it okay to install and use NPM for JS libraries along composer in laravel because laravel dependency already includes composer. Thanks.
Yes. This is standard Laravel functionality.
NPM regulates the JS packages in the node_modules folder.
Both NPM and NODE.js need to be installed on your machine: https://blog.teamtreehouse.com/install-node-js-npm-windows
Composer regulates the PHP packages in the vendor folder.
This also needs to be installed separately on your machine: https://laravel.com/docs/4.2
Not sure what you mean by:
... because laravel dependency already includes composer.
Composer is needed anyway, no need to see it as a complication.

Package.json in MVC template with VSCode

I imported MVC template by running dotnet new mvc -lang C#. I got default template here but I noticed it's missing package.json file.
How can I add package.json in VSCode editor to this template to add other required references ?.
You can use npm init command from node package manager.
Open Nodejs command prompt.
Navigate to project directory.
type npm init command.
Specify basic details like name, version, description, entry point etc.
This will create basic of package.json. Then, you can use npm install <package> --save to install new npm packages in your project.
Other option is, you can create package.json manually.

Which command do I use to generate the build of a Vue app?

What should I do after developing a Vue app with vue-cli?
In Angular there was some command that bundle all the scripts into one single script.
Is there something the same in Vue?
I think you've created your project like this:
vue init webpack myproject
Well, now you can run
npm run build
Copy index.html and /dist/ folder into your website root directory. Done.
If you've created your project using:
vue init webpack myproject
You'd need to set your NODE_ENV to production and run, because the project has web pack configured for both development and production:
NODE_ENV=production npm run build
Copy dist/ directory into your website root directory.
If you're deploying with Docker, you'd need an express server, serving the dist/ directory.
Dockerfile
FROM node:carbon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD . /usr/src/app
RUN npm install
ENV NODE_ENV=production
RUN npm run build
# Remove unused directories
RUN rm -rf ./src
RUN rm -rf ./build
# Port to expose
EXPOSE 8080
CMD [ "npm", "start" ]
in your terminal
npm run build
and you host the dist folder. for more see this video
To deploy your application to prod environment add
"build": "vue-cli-service build --mode prod"
in your scripts in package.json file.
Open your main.js and add
Vue.config.productionTip = false;
right after your imports.
Then open your cli in the project folder and run this command
npm run build
This will make a dist folder in your project directory you may upload that dist folder in your host and your website will be live
If you run into problems with your path, maybe you need to change the assetPublicPath in your config/index.js file to your sub-directory:
http://vuejs-templates.github.io/webpack/backend.html
The vue documentation provides a lot of information on this on how you can deploy to different host providers.
npm run build
You can find this from the package json file. scripts section. It provides scripts for testing and development and building for production.
You can use services such as netlify which will bundle your project by linking up your github repo of the project from their site. It also provides information on how to deploy on other sites such as heroku.
You can find more details on this here
The commands for what specific codes to run are listed inside your package.json file under scripts. Here is an example of mine:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
If you are looking to run your site locally, you can test it with
npm serve
If you are looking to prep your site for production, you would use
npm build
This command will generate a dist folder that has a compressed version of your site.
THIS IS FOR DEPLOYING TO A CUSTOM FOLDER (if you wanted your app not in root, e.g.
URL/myApp/) - I looked for a longtime to find this answer...hope it helps someone.
Get the VUE CLI at https://cli.vuejs.org/guide/ and use the UI build to make it easy. Then in configuration you can change the public path to /whatever/ and link to it URL/whatever.
Check out this video which explains how to create a vue app using CLI if u need more help: https://www.youtube.com/watch?v=Wy9q22isx3U
For NPM => npm run Build
For Yarn => yarn run build
You also can check scripts in package.json file
You write down the below command being at the project root.
npm run build
First Install Vue Cli Globally
npm install -g #vue/cli
To create a new project, run:
vue create project-name
run vue
npm run serve
Vue CLI >= 3 uses the same vue binary, so it overwrites Vue CLI 2 (vue-cli). If you still need the legacy vue init functionality, you can install a global bridge:
Vue Init Globally
npm install -g #vue/cli-init
vue init now works exactly the same as vue-cli#2.x
Vue Create App
vue init webpack my-project
Run developer server
npm run dev
This command is for start the development server :
npm run dev
Where this command is for the production build :
npm run build
Make sure to look and go inside the generated folder called 'dist'.
Then start push all those files to your server.
One way to do this without using VUE-CLI is to bundle the all script files into one fat js file and then reference that big fat javascript file into main template file.
I prefer to use webpack as a bundler and create a webpack.conig.js in the root directory of project. All the configs such as entry point, output file, loaders, etc.. are all stored in that config file. After that, I add a script in package.json file that uses webpack.config.js file for webpack configs and start watching files and create a Js bundled file into mentioned location in webpack.config.js file.
I think you can use vue-cli
If you are using Vue CLI along with a backend framework that handles static assets as part of its deployment, all you need to do is making sure Vue CLI generates the built files in the correct location, and then follow the deployment instruction of your backend framework.
If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app. You can deploy the built content in the dist directory to any static file server, but make sure to set the correct baseUrl
npm run build - this will uglify and minify the codes
save index.html and dist folder in root directory of your website.
free hosting service that you might be interested in -- Firebase hosting.
if you used vue-cli and webpack when you created your project.
you can use just
npm run build command in command line, and it will create dist folder in your project. Just upload content of this folder to your ftp and done.
If you are using npm u can use npm run build but if you are using yarn you can simply run yarn build
If you want to create a build for a domain, you can use the $ npm run build command.
If you're going to build for a sub-domain, follow these instructions:
Create a file that's name is vue.config.js in the root
Write down the below code in the vue.config.js file:
module.export = {
publicPath: '/demo-project',
}
Now run $ npm run build
Note: Use your subdomain name instead of "/demo-project".
If you want to build and send to your remote server you can use cli-service (https://cli.vuejs.org/guide/cli-service.html) you can create tasks to serve, build and one to deploy with some specific plugins as vue-cli-plugin-s3-deploy

Missing node_modules when deploying AngularJS2 application to Bluemix

We're trying to deploy an AngularJS2 application to bluemix but we're missing the folder "node_modules" after the application was deployed to the server. We're using npm to build the application.
I found the following post that is mentioning the problem: (https://developer.ibm.com/answers/questions/181207/npm-install-within-subdirectory-not-creating-node.html)
My question would now be: what's the recommended best practice?
I believe you are installing the node modules using npm install, you also should save those module in your package.json file which you can do that by npm install --save.
The recommended best practice would be to Setup a Build Pipeline.
There could be 3 stages or more:
Build Stage: It builds the app so doing things like npm install there so your folder node_modules gets created for you.
Test Stage: Tests the app so doing things like npm test would run all the tests in your app
Deploy Stage: Once build and deploy stage runs successfully, Deploy will actually deploy the app to the Bluemix domain.