ASP Core pre/post-publish actions to install tools for Angular2 then build - visual-studio

We have a .NET Core project which uses Angular2 as frontend client. This frontend is located in our solution in a Frontend directory.
This frontend contains the package.json and angular-cli.json to isolate all that fron the rest of the .NET project. On ng build, Angular2 compiled files are sent to ../wwwroot directory.
Our project structure:
We want, when someone checkout the project AND on publish (on Azure) to be able to call these actions:
npm install -g angular-cli
cd Frontend && npm install && ng build --prod
How to achieve this in the project.json .NET Core file?
I tried for example, targetting a deployement on Azure, to set this up:
"prepublish": [ "npm install -g angular-cli" ],
"postpublish": [ "cd Frontend && npm install && ng build --prod", "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
But it breaks the deploy. Are both the prepublish and postbublish (with cd Frontend and subsequent commands) valid?
And how to make VisualStudio do the same thing when the people checking out the git repo and hit build?

In general, you may use any tasks runner (gulp, npm tasks, etc) and in postpublish step (or other step like prebuild) just execute appropriate tasks.
As alternative you could even do steps in opposite direction and call dotnet commands (build, deploy, ...) from your, lets say, npm task script. For example, you could look into this repo that is example of using ASP.NET Core and Angular2 with Webpack. They use those npm tasks as entry point of any actions like build, run or deploy:
The npm package.json configuration loads all the required packages for Angular 2 and Webpack. The Webpack packages are all added to the devDependencies. A “npm build” script and also a “npm buildProduction” are also configured, so that the client application can be built using Webpack from the cmd line using “npm build” or “npm buildProduction”.

Related

Create Heroku pipelines with different build command

I have a repo with 2 different build/start commands: one for the app itself, and another to run Storybook. Yes, I know Storybook should be on its own repo but for now we have everything in a single repo.
How can I build 2 pipelines, one that starts with npm build and npm start, and another pipeline that uses npm run build-storybook and npm run storybook?
I can't use a Procfile since they are both on the main branch.
I was working on this exact issue. Unfortunately I was unable to find a solution because Heroku automatically runs the build command on deployment.
I pivoted to using Chromatic because it has built in Storybook deployments.

Laravel Mix before commit

So, there is a tool Laravel Mix which could be run via npm command like npm mix dev or npm mix prod.
Locally I need styles and scripts to be compiled but not minified. So I have to run npm mix dev. But I need to commit only minified versions of such files. And it's not an option to have both versions in a repository - it has to be only minified.
Is there an option so I can use development files locally but before I make a commit they will be minified? And after commit - unmified again (with npm mix dev)

Is it possible to disable ESLint when running npm run build for a React app?

I have an app initiated using Create React App, so npm run build runs react-scripts build. I recently installed prettier and so added a .eslintrc.json file to the project root to load the prettier plugin. npm run build works as expected locally, but, when deploying the app to Heroku, npm run build tries to run ESLint and fails because the plugins are devDependencies rather than dependencies.
Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
From prior wrangling with a similar issue, I know that I can set NPM_CONFIG_PRODUCTION=false in Heroku so that it will install devDependencies, which actually does resolve the deployment issue. Nevertheless, I'm curious to learn if there's another solution that doesn't require setting NPM_CONFIG_PRODUCTION=false.
Is it possible to prevent npm run build in this scenario from running ESLint altogether or to prevent it from trying to access the plugins specified in .eslintrc.json? I acknowledge that adding .eslintrc.json to .gitignore is one solution, but I want the ESLint configuration in my repo.
you can run "npm run eject" to generate webpack configuration files, and then modify "webpack.config.js",delete the eslint configuration

NPM run build not working in Windows specific directory

I am working on a Front End project in Javascript (NPM, Webpack and Babel). I work on Mac all the time but I am having some issues when cloning the project in my PC Windows 10 machine.
It is building properly if I put the project in any directory but when I put the project in the directory where it should be located, Babel doesn't compile the project as expected.
The reason the project should be located there is because I am integrating it with some other tools (Bamboo - Continuous Integration).
npm run build
My builds script is:
"build": npm run clean && cross-env NODE_ENV=production webpack --env.prod=true
ERROR in ./index.js
Module parse failed: C:\opt\bamboo-home\xml-data\build-dir\STA-DEV-
JOB1\node_modules\babel-loader\lib\index.js!C:\opt\bamboo-home\xml-
data\build-dir\STA-DEV-JOB1\src\index.js Unexpected token (24:8)
You may need an appropriate loader to handle this file type.
| const render = (Component, target) => {
| ReactDOM.render(
| <Provider store={store}>
| <AppContainer>
| <Component/>
Does nodeJS or NPM or Webpack or Babel need specific permission over the directories they work on ?
Any help would be appreciated. I am lossing hair here.
Am glad you are using window 10. Use the bash shell on windows 10 to run the command npm run build.
follow this link to learn how you can cd to the directory from the bash shell
I had the same problem, then i found that i need shell bash, so follow the bellow steps:
install Git
go to project folder and right click to access context menu
from there run Git bash here
run the command: npm run build / yarn build
mine working perfectly with this solution.

How to build asp.net webApI and aurelia in VS online together?

I used aurelia-cli to setup my Aurelia application on top of the backend in asp.net WebAPI.
I run backend from visual studio on a port in localhost, which exposes the api endpoints. Then I open git bash from my project directory to do au run which runs my Aurelia frontend on localhost:9000
On Visual Studio online, it builds my backend project even if I made a change to one of the typescript files within Aurelia. But the artifact created by build process doesn’t have any .ts files. This is similar to if I were to publish from visual studio.
To publish Aurelia, I do au build -–env prod separately on git bash from project directory, that bundles files into app-bundle.js and vendor-bundle.js inside wwwroot/scripts directory.
So I have two different projects for Aurelia and webAPI. The question is can I build both together in visual studio online/TFS?
I tried adding a shell script with the au build –-env prod command as a task to my build process. It tried to run from the temp location where it drops the artifacts eg: d:\a\1\s\mycommand.sh . Aurelia isn’t installed there, so I got au command not found error.
If not together, can I run the aurelia project separately from vs online so I get the bundled js files that I can then use to deploy, without having to run the commands from git bash?
Update: after writing this post, I got this post in suggestion How to optimize workflow with single project using Aurelia CLI / ASP.NET Core
which mentions "the au build command is executed in the precompilation target, so when I build or run the ASP.NET Core project from Visual Studio using F5, Aurelia CLI will build and bundle the assets for the Aurelia app into wwwroot as well."
It doesn't say how to do it, that is what I'm trying to achieve. Perhaps asking question as an answer is not advised so I asked it here.
There are many ways that can call au command:
Install Aurelia cli in a folder:
Include aurelia-cli package dependence in package.json file (dependencies or devDependencies) or install it directly through Command line task (Put package.json file in the target folder that you want to call au command)
Add au build command to scripts of package.json
Sample:
{
"name": "autest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"aurelia-cli": "^0.32.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"aubuild": "au build --env stage"
},
"author": "",
"license": "ISC"
}
Install package through NPM build task (Command: install; Working folder with package.json: package.json folder path)
(Option 1) Call NPM command through NPM build task (Command: custom; Working folder with package.json: package.json folder path; Command and arguments: run aubuild)
(Option 2) Call au command through Command Line task (Working folder: Aurelia-cli package installed path; Tool: node_module\.bin\au; Arguments: build --env stage)
Install Aurelia cli in global:
Add command line task (Tool: npm; Arguments: install aurelia-cli -g)
Call au command in any folder
Regarding "the au build command is executed in the precompilation target”, you can try to build the project through Visual Studio task and check the result.

Resources