Code Monkey home page Code Monkey logo

angular-cli-customizer's Introduction

Logo

angular-cli-customizer

A small command-line Node module that allows Angular CLI's Webpack config file to be customized

Installation

npm install @angular/cli -g
npm install angular-cli-customizer -g

Usage

  1. Define a webpack.config.js file at the root of your project containing the Webpack configuration settings you wish modify/add to the Angular CLI's build:
const path = require('path');

module.exports = {
    resolve: {
        alias: {

            // all upgraded AngularJS modules will now be forced to
            // use the same version of AngularJS, removing the
            // "Tried to load angular more than once." warning.
            angular: path.resolve(__dirname, 'node_modules/angular')
        }
    }
};
  1. Use the command line interface exposed by this module - cng (think "customized" ng) - exactly as you would with the @angular/cli module (ng):
cng serve --open

API

The cng command is simply a wrapper for the ng command, so its API is identical to the standard ng command!

Why is this necessary?

Angular's CLI is a fantastic tool for generating and developing Angular applications. Unfortunately, it has one major flaw - at the time of writing, there is no way to customize or extend the CLI's stock functionality. Even though the Angular CLI is built on top of the infinitely configurable Webpack, the CLI doesn't allow its internal Webpack configuration to be altered.

What does this module do?

This module does some acrobatics (modifying the require function) to surgically replace the internal function (buildConfig()) that is responsible for generating the CLI's Webpack configuration object. The replacement function takes the result of the original buildConfig() call, merges in any changes defined in the custom webpack.config.js file, and returns the merged result.

Other than that, the cng command is simply a wrapper for the ng command.

How do I know what to modify?

If you run ng eject, the Angular CLI will create a webpack.config.js file at the root of your project's directory that contains the configuration it uses at runtime. You can use this file as a reference when designing your own webpack.config.js file that will augment this configuration.

Note that running ng eject prevents the usage of some CLI features; to "uneject", delete the generated webpack.config.js and flip the ejected property to false in your project's .angular.cli.json.

Isn't this a hack?

Yep. It depends on internal implementation details of the CLI, which could change during any update of the @angular/cli package. Hopefully a better customization solution will be eventually be built into the CLI.

angular-cli-customizer's People

Contributors

nfriend avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.