Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular cli hook

I am looking for way to modify output of build function from

ng build --prod

would like to add some bootstrap css files to head section of index.html, change name index.html => index.php etc.

how to do it ?

like image 900
bensiu Avatar asked Jul 12 '16 20:07

bensiu


People also ask

What is hook in Angular?

The hooks give you the opportunity to act on a component or directive instance at the appropriate moment, as Angular creates, updates, or destroys that instance. Each interface defines the prototype for a single hook method, whose name is the interface name prefixed with ng .

What is Devkit in Angular?

DevKit was built to provide libraries that can be used to manage, develop, deploy, and analyze your code. DevKit has a schematics-cli command line tool that you can use to create your own Schematics.

What are lifecycle hooks?

A lifecycle hook provides a specified amount of time (one hour by default) to wait for the action to complete before the instance transitions to the next state.

How many lifecycle hooks are there in Angular?

Angular gives us 8 hooks to allow us to tap into the lifecycle of our components and trigger actions at specific points in the lifecycle.


1 Answers

You can customise the implementation from the source code. This section explains how you can proceed.

In particular, you can change the following lines from addon/ng2/models/webpack-build-common.ts.

new HtmlWebpackPlugin({
    template: path.resolve(projectRoot, `./${sourceDir}/index.php`),
    chunksSortMode: 'dependency'
  })

For the CSS resources, they can be packaged directly if you use Webpack Angular CLI.

EDIT

The key index in the apps nodes can be modified in the angular-cli.json file. The line should be changed to

"index": "index.php",
like image 186
Nicolas Henneaux Avatar answered Oct 05 '22 10:10

Nicolas Henneaux