Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular CLI Webpack (ngw)

This package provides an opportunity to modify @angular/cli project's webpack configuration without "ejecting".

Build Status npm version dependencies Status Coverage Status Coverage Status

Installation

For angular 6:

$ npm i -g @angular/cli # before usage you need install cli
$ ng new my-project && cd my-project # go into any project on angular
$ npm i -D ngw # installing an improved cli-eject
$ ./node_modules/.bin/ngw --set-up # run via terminal in project root
Set up went successfully!

For angular 5 use npm i -D ngw@angular5

Usage:

Last command installation (ngw --set-up) makes two things:

  1. Changes scripts in package.json that starts from ng to ngw
  2. Creates file ngw.config.ts in project root where you can redefine webpack.Configuration used by @angular/cli

So just make changes to the webpack config in appeared ngw.config.ts

You may like to do npm i -D @types/webpack for better experience.

Example

Removes unused selectors from your CSS

This little piece of code in your ngw.config removes unused selectors from your CSS:

const PurifyCSSPlugin = require('purifycss-webpack');
const path = require('path');
const glob = require('glob');

export default function(config) {
    config.plugins.push(
      new PurifyCSSPlugin({
        paths: glob.sync(path.join(__dirname, '**/*.html'))
      })
    );
    return config;
}

Prod and dev mode modifications (ngw.config.ts)

export default function(config, options) {
  //common config modification
  ...
  switch(options.buildOptions.enviroment) {
    case 'prod':
      config = productionModificationsMerged(config);
      break
    case 'dev':
      //etc
  }
}

Caution

For complex cases it's more appropriate to use ng eject command. Default building process could be changed significanlty in further @angular/cli releases so your customization could break (or became broken).

About

Webpack configuration modifier for @angular/cli

Topics

Resources

Stars

67 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages