npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lime.it/ng-dockerize

v1.2.0

Published

Utility library with schematics to easily set up an angular app for a container deployment with a dynamic environment variables configuration.

Downloads

6

Readme

@lime.it/ng-dockerize

Version CircleCI Downloads/week License

Utility library with schematics to easy set up an angular app for a container deployment with a dynamic environment variables configuration.

The library automatically set up the configuration files to create an nginx based docker image for your angular app with dynamic runtime, multi environments, configuration. It also provides a service to access the merged compile-time and runtime-configuration and an APP_INITIALIZER to ensure it to be loaded before application start.

It is also possible to specify environment variables overrides, setting variables in the form APP_<path> where <path> is a __ separeted object path to the value in the evironment object:

APP_path__to__value=3

corresponds to:

{
  path: {
    to: {
      value: 3
    }
  }
}

How to install and use

Install through npm:

npm install @lime.it/ng-dockerize

And then use the init schematic:

ng g @lime.it/ng-dockerize:init

Otherwise simply add with angular-cli

ng add @lime.it/ng-dockerize

You will find in your angular workspace two new files:

  • Dockerfile: configured to build an nginx based image with contents from the ./dist/{your_app} folder
  • nginx.conf: configured to set up an alias for assets/environment.json based on the value of the environment value APP_ENVIRONMENT

Moreover, your app main NgModule will import the NgDockerizeModule.

The NgDockerizeModule provides a service (EnvironmentService) which enables to access the dynamic configuration, and an APP_INITIALIZER to ensure the configuration to be loaded before the application starts.

In order to complete the setup, you must provide a value for the token NG_DOCKERIZE_OPTIONS, setting the current compile-time environment and optionally a debug environment.

Example setup

app.module.ts

import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { NgDockerizeModule, NG_DOCKERIZE_OPTIONS } from '@lime.it/ng-dockerize';
import { environment } from 'src/environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgDockerizeModule
  ],
  providers: [
    // { provide:NG_DOCKERIZE_OPTIONS, useValue: { environment:environment } } // for production
    { provide:NG_DOCKERIZE_OPTIONS, useValue: { environment: environment, debug: { production: false, environment: "test" } } }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { EnvironmentService } from '@lime.it/ng-dockerize';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  
  constructor(public env:EnvironmentService) {
    
  }
}

app.component.html

Environment: <strong>{{env.environment?.environment}}</strong>

docker commands

docker build -t my-dockerized-app
docker run -d -e APP_ENVIRONMENT=staging -p 80:80 my-dockerized-app