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

@islavi/ng-component-lab

v1.2.0

Published

Build Angular 2 components in a controlled, isolated environment. This is fork from <a href='https://github.com/synapse-wireless-labs/component-lab.git'>https://github.com/synapse-wireless-labs/component-lab.git</a> which use angular 2 and fix some bugs.

Downloads

3

Readme

Ng Component Lab

A component development and testing tool built for Angular 2, inspired by React Storybook This is a fork from component-lab with some bug fixes and with angular 2 instead of angular 4.

Getting Started

Installation and Configuration

  1. Install NG Component Lab: Via npm:
npm install @islavi/ng-component-lab --save-dev

Via yarn:

yarn add @islavi/ng-component-lab --dev
  1. The best way to understand how to configure ng-component-lab is to download the example from https://github.com/islavi/ng-component-lab-example The following files should be configured:

ng-lab-webpack.config.js file in the root of your project This is webpack configuration file for ng-component-lab Below is example file:

var webpack = require('webpack');
var path = require('path');

var webpackConfig = {

  devtool: 'source-map',

  plugins: [],

  resolve: {
    extensions: ['.ts', '.js'],
    modules: [path.resolve(__dirname, 'node_modules')]
  },

  module: {
    loaders: [
      {
        test: /\.ts$/,
        loaders: [
          'awesome-typescript-loader',
          'angular2-template-loader',
          'angular2-router-loader'
        ]
      },
      { test: /\.css$/, loaders: ['to-string-loader', 'css-loader'] },
      { test: /\.html$/, loader: 'raw-loader' }
    ]
  },

  node: {
    global: true,
    crypto: 'empty',
    __dirname: true,
    __filename: true,
    process: true,
    Buffer: false,
    clearImmediate: false,
    setImmediate: false
  }
};

module.exports = webpackConfig;
  1. Create folder .lab in the root of your application, and create two files inside of it: First file: ng-component-lab.config.js - configuration file of ng-component-lab. Example:
var getWebPackConfig = require('./../ng-lab-webpack.config');

module.exports = {
  webpackConfig: getWebPackConfig,
  host: 'localhost',
  port: 6007,
  include: [],
  suites: {
    feature: './.lab/ng-lab-configuration.module.ts'
  }
}; 

Second file: ng-lab-configuration.module.ts - configuration module for ng-component-lab. Example:

import { createLab } from '@islavi/ng-component-lab';
import { ComponentsModule } from './../components/components.module';

createLab({
  /**
  * NgModule to import. All components and pipes must be exported
  * by this module to be useable in your experiments
  */
  ngModule: ComponentsModule,
  /**
  * Function that returns an array of experiments.
  *
  * Here is an example using webpack's `require.context` to
  * load all modules ending in `.exp.ts` and returning thier
  * default exports as an array:
  */
  loadExperiments() {
    const context = (require as any).context('./../experiments/', true, /\.exp\.ts/);
    var result = context.keys().map(context).map(mod => mod.default);
    return result;
  }
});

Writing Experiments

  1. Create folder called experiments in the root folder.

  2. Create a component-name.exp.ts file in experiments folder (example: button.component.exp.ts). Experiments can also provide both a template context object and an array of styles. Some cases can be ignored by using xcase instead of case. Example:

import { experimentOn } from '@islavi/ng-component-lab';
import { ButtonComponent } from "./../components/button.component";

export default experimentOn('Button')
  .case('Primary Button', {
    styles: [`
      my-button /deep/ .my-button {
        border: solid 1px darkblue;
        color: white;
        border-radius: 4px;
        padding: 2px 10px;
        cursor: pointer;
      }
      my-button /deep/ .my-button-primary {
        background-color: blue;
      }
    `],
    template: `
      <my-button>Button</my-button>
    `
  })
  .case('Warning Button', {
    context: {
      buttonLabel: 'Warning!',
    },
    styles: [`
      my-button /deep/ .my-button {
        border: solid 1px darkblue;
        color: white;
        border-radius: 4px;
        padding: 2px 10px;
        cursor: pointer;
      }
      my-button /deep/ .my-button-warning {
        border: solid 1px darkred;
        background-color: red;
      }
    `],
    template: `
      <my-button [type]="'warning'">
        {{ buttonLabel }}
      </my-button>
    `
  })
  .xcase('Not Yet Implemented', {
    template: `
      <my-button raised>Raised Button</my-button>
    `
  })

Running Ng Component Lab

  1. In the scripts section of your package.json add a script to start Component Lab:
{
  "scripts": {
    "lab": "ng-component-lab --config .lab/ng-component-lab.config.js -- feature"
  }
}

Note: feature is the suite name.

  1. Start the Component Lab server using npm or yarn:

Via npm:

npm run lab

Via yarn:

yarn run lab

Bulding ng-component-lab from your project

  1. In the scripts section of your package.json add a script to build Component Lab:
{
  "scripts": {
    "build-lab": "ng-component-lab --config .lab/ng-component-lab.config.js --build -- feature"
  }
}

Note: feature is the suite name. .dist is the default floder where the build bundle will be created. you can override this in your webpack config. Example:

  "output": {
    "path": ".somePath"
  }  
  1. Start the Component Lab build using npm or yarn:

Via npm:

npm run build-lab

Via yarn:

yarn run build-lab

Bulding ng-component-lab from src

  1. Install all dependencies:

Via npm:

npm install

Via yarn:

yarn install
  1. Build ng-component-lab:
    Via npm:
npm run build

Via yarn:

yarn run build

This will create a folder called "release".