Repository: trekhleb/angular-library-seed
Branch: master
Commit: 054c1a1f158c
Files: 46
Total size: 51.4 KB
Directory structure:
gitextract_qt_pvz36/
├── .editorconfig
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── README.md
├── demo/
│ ├── .gitignore
│ ├── README.md
│ ├── esm/
│ │ ├── src/
│ │ │ ├── app/
│ │ │ │ ├── app.component.ts
│ │ │ │ └── app.module.ts
│ │ │ ├── index.ejs
│ │ │ ├── main-aot.ts
│ │ │ ├── main-jit.ts
│ │ │ └── polyfills.browser.ts
│ │ ├── tsconfig-aot.json
│ │ ├── tsconfig.json
│ │ ├── webpack-aot.config.js
│ │ └── webpack.config.js
│ ├── gulpfile.js
│ ├── package.json
│ └── umd/
│ ├── app/
│ │ ├── app.component.ts
│ │ └── app.module.ts
│ ├── index.html
│ ├── main.ts
│ └── systemjs.config.js
├── gulpfile.js
├── karma-test-entry.ts
├── karma.conf.ts
├── package.json
├── src/
│ ├── components/
│ │ ├── index.ts
│ │ └── tick-tock/
│ │ ├── index.ts
│ │ ├── tick-tock.component.html
│ │ ├── tick-tock.component.scss
│ │ ├── tick-tock.component.spec.ts
│ │ └── tick-tock.component.ts
│ ├── index.ts
│ ├── services/
│ │ ├── index.ts
│ │ └── tick-tock/
│ │ ├── index.ts
│ │ ├── tick-tock.service.spec.ts
│ │ └── tick-tock.service.ts
│ └── tick-tock.module.ts
├── tsconfig-aot.json
├── tsconfig.json
├── tslint.json
├── webpack-test.config.ts
└── webpack-umd.config.ts
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
# http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
================================================
FILE: .gitignore
================================================
# Node
node_modules
npm-debug.log
# Yarn
yarn-error.log
# JetBrains
.idea/
# VS Code
.vscode/
# Windows
Thumbs.db
Desktop.ini
# Mac
.DS_Store
# Temporary files
coverage/
dist
docs
tmp
================================================
FILE: .npmignore
================================================
# Node
node_modules
npm-debug.log
# Yarn
yarn-error.log
# JetBrains
.idea/
# VS Code
.vscode/
# Windows
Thumbs.db
Desktop.ini
# Mac
.DS_Store
# Temporary files
coverage/
demo/
docs
tmp
# Library files
src/
================================================
FILE: .travis.yml
================================================
sudo: required
dist: trusty
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
language: node_js
node_js:
- node
script:
- npm run ci
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
cache:
yarn: true
notifications:
email: false
after_success:
- npm run codecov
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2017 Oleksii Trekhleb
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# `angular-library-seed` - the starter for Angular libraries
[](https://travis-ci.org/trekhleb/angular-library-seed)
[](https://codecov.io/gh/trekhleb/angular-library-seed)
[](https://badge.fury.io/js/angular-library-seed)
> Seed project for [Angular](https://angular.io/) libraries that are [AOT](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html)/[JIT](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) compatible and that use external [SCSS](http://sass-lang.com/)-styles and HTML-templates.
This project contains TickTock library example. The library itself is small and the only thing it does is [displaying current time](http://embed.plnkr.co/VbO1hldrCfF6ITG6VvGG/) (Plunker example). But what **most important** is that the project contains **reusable environment** for the libraries that allows to build, test, lint, document, explore and publish them.
> [Read more](https://medium.com/@trekhleb/how-to-create-aot-jit-compatible-angular-4-library-with-external-scss-html-templates-9da6e68dac6e) about architectural **challenges** and **solutions** used in this repository.
# You might find this project helpful if
- You want to create library for **Angular 4**.
- You want your library to be ready for further **AOT** or **JIT** compilation.
- You want your library to be ready for further usage **directly in browsers** (let's say [UMD](https://github.com/umdjs/umd) bundle loaded by [SystemJS](https://github.com/systemjs/systemjs)).
- You want to write component styles in **external SCSS files**.
- You want to write component templates in **external HTML files**.
- You want to have **watch-mode** for library builds (including AOT build).
# Main Features
- **AOT/JIT** compatible library build via [Angular Compiler](https://www.npmjs.com/package/@angular/compiler-cli) (ngc).
- **UMD** build via [Webpack](https://webpack.js.org/) that allows you to use your library for browser builds. You may play with it on [Plunker](http://embed.plnkr.co/VbO1hldrCfF6ITG6VvGG/).
- **Testing** with [Karma](https://karma-runner.github.io/1.0/index.html) and [Jasmine](https://jasmine.github.io/).
- **Test coverage** report via [Istanbul](https://github.com/gotwarlost/istanbul).
- **Watch modes** for building and testing procedures that makes developing process easier.
- **Linting** with [TSLint](https://palantir.github.io/tslint/) and [Codelyzer](https://github.com/mgechev/codelyzer) for static code analysis.
- **Exploring your build** via [Sourcemap Explorer](https://www.npmjs.com/package/source-map-explorer) that shows you a treemap visualization to help you debug where all the code is coming from.
- **Documentation generation** via [Compodoc](https://github.com/compodoc/compodoc). Take a look at [documentation example](https://trekhleb.github.io/angular-library-seed/).
- **Documentation hosting** via [GitHub Pages](https://pages.github.com/).
- **AOT/JIT/UMD demos** via [Webpack](https://webpack.js.org/) and [SystemJS](https://github.com/systemjs/systemjs) that allows you to test library builds.
- **Continuous integration** with [Travis CI](https://travis-ci.org/).
- **Code coverage** badge via [Codecov](https://codecov.io) as a reminder to cover code with tests.
# Quick Start
```bash
# Clone the repository
git clone https://github.com/trekhleb/angular-library-seed.git
# Go to repository folder
cd angular-library-seed
# Install all dependencies
yarn install
# Build the library
yarn build
```
# File Structure
```
angular-library-seed
├─ demo * Folder for demo applications (MAY BE DELETED if not required)
| ├─ esm * AOT/JIT demo project
| ├─ umd * UMD demo project
| └─ ... * More details about this folder may be found in demo folder README file.
|
├─ src * Library sources home folder (THE PLACE FOR YOUR LIBRARY SOURCES)
| ├─ components * Example of library components with tests
| ├─ services * Example of library services with tests
| ├─ index.ts * Library entry point that is used by builders
| └─ tick-tock.module.ts * Example of library module
|
├─ .editorconfig * Common IDE configuration
├─ .gitignore * List of files that are ignored while publishing to git repo
├─ .npmignore * List of files that are ignored while publishing to npm
├─ .travis.yml * Travic CI configuration
├─ LICENSE * License details
├─ README.md * README for you library
├─ gulpfile.js * Gulp helper scripts
├─ karma-test-entry.ts * Entry script for Karma tests
├─ karma.conf.ts * Karma configuration for our unit tests
├─ package.json * NPM dependencies, scripts and package configuration
├─ tsconfig-aot.json * TypeScript configuration for AOT build
├─ tsconfig.json * TypeScript configuration for UMD and Test builds
├─ tslint.json * TypeScript linting configuration
├─ webpack-test.config.ts * Webpack configuration for building test version of the library
├─ webpack-umd.config.ts * Webpack configuration for building UMD bundle
└─ yarn.lock * Yarn lock file that locks dependency versions
```
# Getting Started
## Dependencies
#### Node/NPM
Install latest Node and NPM following the [instructions](https://nodejs.org/en/download/). Make sure you have Node version ≥ 7.0 and NPM ≥ 4.
- `brew install node` for Mac.
#### Yarn
[Yarn package manager](https://yarnpkg.com/en/) is optional but highly recommended. If you prefer to work with `npm` directly you may ignore this step.
Yarn installs library dependencies faster and also locks theirs versions. It has [more advantages](https://yarnpkg.com/en/) but these two are already pretty attractive.
Install Yarn by following the [instructions](https://yarnpkg.com/en/docs/install).
- `brew install yarn` for Mac.
## Installing
- `fork` this repository.
- `clone` your fork to your local environment.
- `yarn install` to install required dependencies (or `npm i`).
## Replace `TickTock` library with your own library
This step may be optional at first since you might just want to play with existing library example.
Once you're ready to develop your own library you should do the following.
- Check and re-configure `package.json` fields like `name`, `version`, `keywords`, `description` etc. You may read about specifics of npm's [package.json handling](https://docs.npmjs.com/files/package.json) to do that.
- Replace the content of `src` folder with your library sources. Your library must have `index.ts` file as an entry point for further building.
- Update `demo` sources to make them consume your library in case if you want to keep the demo folder.
## Build the library
- `yarn build` for building the library once (both ESM and AOT versions).
- `yarn build:watch` for building the library (both ESM and AOT versions) and watch for file changes.
You may also build UMD bundle and ESM files separately:
- `yarn build:esm` - for building AOT/JIT compatible versions of files.
- `yarn build:esm:watch` - the same as previous command but in watch-mode.
- `yarn build:umd` - for building UMD bundle only.
- `yarn build:umd:watch` - the same as previous command but in watch-mode.
## Other commands
#### Lint the code
- `yarn lint` for performing static code analysis.
#### Test the library
- `yarn test` for running all your `*.spec.ts` tests once. Generated code coverage report may be found in `coverage` folder.
- `yarn test:watch` for running all you `*.spec.ts` and watch for file changes.
#### Generate documentation
- `yarn docs` for generating documentation locally.
- `yarn gh-pages` for generating documentation and uploading it to GitHub Pages. [Documentation example](https://trekhleb.github.io/angular-library-seed/).
#### Explore the bundle
- `yarn explorer` to find out where all your code in bundle is coming from.
#### Bump library version
- `npm version patch` to increase library version. [More on bumping](https://docs.npmjs.com/cli/version).
`preversion` script in this case will automatically run project testing and linting in prior in order to check that the library is ready for publishing.
#### Publish library to NPM
- `npm publish` to publish your library sources on [npmjs.com](https://www.npmjs.com/). Once the library is published it will be [available for usage](https://www.npmjs.com/package/angular-library-seed) in npm packages.
`prepublishOnly` script in this case will automatically run project testing and linting in prior in order to check that the library is ready for publishing.
#### Cleaning
- `yarn clean:tmp` command will clean up all temporary files like `docs`, `dist`, `coverage` etc.
- `yarn clean:all` command will clean up all temporary files along with `node_modules` folder.
# Library development workflow
In order to debug your library in browser you need to have Angular project that will consume your library, build the application and display it. For your convenience all of that should happen automatically in background so once you change library source code you should instantly see the changes in browser.
There are several ways to go here:
- Use your **real library-consumer project** and link your library to it via `yarn link` command (see below).
- Use [demo applications](https://github.com/trekhleb/angular-library-seed/tree/master/demo) that are provided for your convenience as a part of this repository.
- Use [Angular-CLI](https://cli.angular.io/) to generate library-consumer project for you and then use `yarn link` to link your library to it.
### Using demo applications
You may take advantage of watch-modes for both library build and [demo-projects](https://github.com/trekhleb/angular-library-seed/tree/master/demo) builds in order to see changes to your library's source code immediately in your browser.
To do so you need to:
1. Open two console instances.
2. Launch library build in watch mode in first console instance by running `yarn build:watch` (assuming that you're in `angular-library-seed` root folder).
3. Launch demo project build (JIT version) in watch-mode by running `yarn start` in second console instance (assuming that you're in `angular-library-seed/demo` folder).
As a result once you change library source code it will be automatically re-compiled and in turn your JIT demo-project will be automatically re-built and you will be able to see that changes in your browser instantly.
For more details about demo projects, their folder structure and npm commands please take a look at [demo projects README](https://github.com/trekhleb/angular-library-seed/tree/master/demo).
### Using `yarn link`
In you library root folder:
```bash
# Create symbolic link
yarn link
# Build library in watch mode
yarn build:watch
```
In you project folder that should consume the library:
```bash
# Link you library to the project
yarn link "angular-library-seed"
# Build your project. In case of Angular-CLI use the following command.
ng serve --aot
```
Then you need to import your library into your project's source code.
Now, once you update your library source code it will automatically be re-compiled and your project will be re-built so you may see library changes instantly.
[More information](https://yarnpkg.com/en/docs/cli/link) about `yarn link` command.
> At the moment of publishing this project there is a [bug](https://github.com/angular/angular-cli/issues/3854) exists when using `yarn link` in combination with Angular CLI. The issue is caused by having `node_modules` folder inside linked library. There is a [workaround](https://github.com/angular/angular-cli/issues/3854#issuecomment-274344771) has been provided that suggests to add a `paths` property with all Angular dependencies to the `tsconfig.json` file of the Angular CLI project like it is shown below:
```
{
"compilerOptions": {
"paths": { "@angular/*": ["../node_modules/@angular/*"] }
}
}
```
================================================
FILE: demo/.gitignore
================================================
esm/dist
esm/lib
esm/src/**/*.ngfactory.ts
esm/src/**/*.ngsummary.json
node_modules
umd/lib
================================================
FILE: demo/README.md
================================================
# `angular-library-seed` demo projects
> This folder contains two demo-projects (`esm` and `umd` folders) for [angular-library-seed](https://github.com/trekhleb/angular-library-seed). These demo projects may help you to test whether your library supports AOT/JIT/UMD builds or not.
>
> - `esm` folder contains Angular project that is built using [@angular/compiler](https://www.npmjs.com/package/@angular/compiler) and [Webpack](https://webpack.js.org/). This demo project utilizes ESM (pure ES2015) sources of your library to do two kind of compilations:
> - [AOT](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) (ahead-of-time) compilation.
> - [JIT](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) (just-in-time) compilation.
>
> - `umd` folder contains Angular project that is being built and assembled in browser by [SystemJS](https://github.com/systemjs/systemjs). This demo project utilizes [UMD](https://github.com/umdjs/umd) bundle of your library.
Demo-projects are created as an alternative to `npm link` command. You may simply delete this `demo` folder if you prefer to use [yarn link](https://yarnpkg.com/en/docs/cli/link) instead to check how your library is being built.
# Quick Start
```bash
# Assuming the you are already in angular-library-seed/demo folder
# Install all dependencies
yarn install
# Start watching library dist folder and do JIT project build in watch mode.
yarn start
# Or you may simply build AOT/JIT/UMD versions all at once by running the following command
yarn build
```
# File Structure
```
angular-library-seed
└─ demo * Folder for demo applications (MAY BE DELETED if not required)
├─ esm * AOT/JIT demo project
| └─ dist * This folder will contain project ESM builds
| | ├─ aot * This folder contains project build made via AOT compilation
| | | └─ index.html * <-- RUN THIS FILE TO CHECK AOT BUILD
| | |
| | └─ jit * This folder contains project build made via JIT compilation
| | └─ index.html * <-- RUN THIS FILE TO CHECK JIT BUILD
| |
| ├─ lib * Temporary folder with a copy of your library built sources
| ├─ src
| | ├─ app * Demo application sources. Adopt them with your library.
| | ├─ index.ejs * Main application template.
| | ├─ main-aot.ts * AOT main entry.
| | ├─ main-jit.ts * JIT main entry.
| | └─ polyfills.browser.ts * Browser polyfills.
| |
| ├─ tsconfig-aot.json * TypeScript configuration for AOT build.
| ├─ tsconfig.json * TypeScript configuration for JIT build.
| ├─ webpack-aot.config.js * Webpack configuration for AOT build.
| └─ webpack.config.js * Webpack configuration for JIT build.
|
├─ umd * UMD demo project
| ├─ app * Demo application sources. Adopt them with your library.
| ├─ lib * Temporary folder with a copy of your library built sources
| ├─ index.html * <-- RUN THIS FILE TO CHECK UMD BUILD
| ├─ main.ts * Main application entry file.
| └─ systemjs.config.js * SystemJS configuration.
|
├─ .gitignore * List of files that are ignored while publishing to git repository
├─ gulpfile.js * Gulp helper scripts for building demos
├─ package.json * NPM dependencies and helper scripts for building demos
└─ yarn.lock * Yarn dependency versions lock for demo applications
```
# Getting Started
## Dependencies
#### Node/NPM
Install latest Node and NPM following the [instructions](https://nodejs.org/en/download/). Make sure you have Node version ≥ 7.0 and NPM ≥ 4.
- `brew install node` for Mac.
#### Yarn
Install Yarn by following the [instructions](https://yarnpkg.com/en/docs/install).
- `brew install yarn` for Mac.
## Installing
- Switch to `demo` folder in your console.
- `yarn install` to install required dependencies.
## Replace `TickTock` library related code with your own library tags and imports
This step may be optional at first since you might just want to build demo projects with TickTock library example.
Once you're ready to develop your own library you should do the following.
- Adjust source codes of `angular-library-seed/demo/esm/src/app/*.ts` files for AOT/JIT builds.
- Adjust source codes of `angular-library-seed/demo/umd/app/*.ts` files for UMD builds.
## Build demo projects
- `yarn build` for building AOT, JIT and UMD demo versions all at once.
You may also build projects separately:
- `yarn build:jit` - for building JIT version of demo project.
- `yarn build:aot` - for building AOT version of demo project.
- `yarn build:umd` - for building UMD version of demo project.
To see your library in action launch the following files in your browser:
- `angular-library-seed/demo/esm/dist/jit/index.html` file for JIT build
- `angular-library-seed/demo/esm/dist/aot/index.html` file for AOT build
- `angular-library-seed/demo/umd/index.html` file for UMD build
## Build JIT project in watch mode
- `yarn start` for building JIT version of demo project and start watching for library changes.
This command may be used simultaneously in combination with [angular-library-seed](https://github.com/trekhleb/angular-library-seed)'s `yarn build:watch`. As a result once you change library source code it will be automatically re-compiled and in turn your JIT demo-project will be automatically re-built and you will be able to see that changes in your browser instantly.
See [Development Workflow](https://github.com/trekhleb/angular-library-seed#development-workflow) section of [angular-library-seed](https://github.com/trekhleb/angular-library-seed)'s README for more details.
## Other commands
#### Cleaning
- `yarn clean:tmp` command will clean up all temporary files like `dist`, `lib`, `*.ngsummary.json` etc.
- `yarn clean:all` command will clean up all temporary files along with `node_modules` folder.
================================================
FILE: demo/esm/src/app/app.component.ts
================================================
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: ``
})
export class AppComponent {
public header: string = 'UMD Demo';
}
================================================
FILE: demo/esm/src/app/app.module.ts
================================================
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { TickTockModule } from '../../lib';
@NgModule({
imports: [ BrowserModule, TickTockModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
================================================
FILE: demo/esm/src/index.ejs
================================================
<%= htmlWebpackPlugin.options.title %>
Loading demo...
================================================
FILE: demo/esm/src/main-aot.ts
================================================
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from './app/app.module.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
================================================
FILE: demo/esm/src/main-jit.ts
================================================
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
================================================
FILE: demo/esm/src/polyfills.browser.ts
================================================
// Polyfills
// import 'ie-shim'; // Internet Explorer 9 support
// import 'core-js/es6';
// Added parts of es6 which are necessary for your project or your browser support requirements.
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/es6/weak-map';
import 'core-js/es6/weak-set';
import 'core-js/es6/typed';
import 'core-js/es6/reflect';
// see issue https://github.com/AngularClass/angular2-webpack-starter/issues/709
// import 'core-js/es6/promise';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
================================================
FILE: demo/esm/tsconfig-aot.json
================================================
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"noEmit": true,
"declaration": false,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"skipLibCheck": true,
"lib": [
"es2015",
"dom"
]
},
"include": [
"src/**/*.ts"
]
}
================================================
FILE: demo/esm/tsconfig.json
================================================
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"skipLibCheck": true,
"lib": [
"es2015",
"dom"
]
},
"include": [
"./src/**/*.ts"
],
"exclude": [
"./src/main-aot.ts"
]
}
================================================
FILE: demo/esm/webpack-aot.config.js
================================================
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const config = {
devtool: 'source-map',
entry: {
polyfills: path.resolve(__dirname, 'src', 'polyfills.browser.ts'),
main: path.resolve(__dirname, 'src', 'main-aot.ts')
},
resolve: {
extensions: ['.js', '.ts']
},
output: {
path: path.resolve(__dirname, 'dist', 'aot'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: path.resolve(__dirname, 'tsconfig.json')
}
}
]
}
]
},
plugins: [
new webpack.ProgressPlugin(),
/*
* Plugin: HtmlWebpackPlugin
* Description: Simplifies creation of HTML files to serve your webpack bundles.
* This is especially useful for webpack bundles that include a hash in the filename
* which changes every compilation.
*
* See: https://github.com/ampedandwired/html-webpack-plugin
*/
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.ejs'),
title: 'Angular Library Starter',
inject: 'body'
}),
/**
* Plugin: ContextReplacementPlugin
* Description: Provides context to Angular's use of System.import
*
* @see: https://github.com/angular/angular/issues/11580
*/
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
path.resolve(__dirname, 'src'),
{}
),
/*
* Plugin: CommonsChunkPlugin
* Description: Shares common code between the pages.
* It identifies common modules and put them into a commons chunk.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
* See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
*/
new CommonsChunkPlugin({
name: 'polyfills',
chunks: ['polyfills']
}),
// This enables tree shaking of the vendor modules
new CommonsChunkPlugin({
name: 'vendor',
chunks: ['main'],
minChunks: module => /node_modules/.test(module.resource)
}),
// Specify the correct order the scripts will be injected in
new CommonsChunkPlugin({
name: ['polyfills', 'vendor'].reverse()
}),
]
};
module.exports = config;
================================================
FILE: demo/esm/webpack.config.js
================================================
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const config = {
devtool: 'source-map',
entry: {
polyfills: path.resolve(__dirname, 'src', 'polyfills.browser.ts'),
main: path.resolve(__dirname, 'src', 'main-jit.ts')
},
resolve: {
extensions: ['.js', '.ts']
},
output: {
path: path.resolve(__dirname, 'dist', 'jit'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: path.resolve(__dirname, 'tsconfig.json')
}
}
]
}
]
},
plugins: [
new webpack.ProgressPlugin(),
/*
* Plugin: HtmlWebpackPlugin
* Description: Simplifies creation of HTML files to serve your webpack bundles.
* This is especially useful for webpack bundles that include a hash in the filename
* which changes every compilation.
*
* See: https://github.com/ampedandwired/html-webpack-plugin
*/
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.ejs'),
title: 'Angular Library Starter',
inject: 'body'
}),
/**
* Plugin: ContextReplacementPlugin
* Description: Provides context to Angular's use of System.import
*
* @see: https://github.com/angular/angular/issues/11580
*/
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
path.resolve(__dirname, 'src'),
{}
),
/*
* Plugin: CommonsChunkPlugin
* Description: Shares common code between the pages.
* It identifies common modules and put them into a commons chunk.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
* See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
*/
new CommonsChunkPlugin({
name: 'polyfills',
chunks: ['polyfills']
}),
// This enables tree shaking of the vendor modules
new CommonsChunkPlugin({
name: 'vendor',
chunks: ['main'],
minChunks: module => /node_modules/.test(module.resource)
}),
// Specify the correct order the scripts will be injected in
new CommonsChunkPlugin({
name: ['polyfills', 'vendor'].reverse()
}),
],
devServer: {
port: 8000,
historyApiFallback: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
},
};
module.exports = config;
================================================
FILE: demo/gulpfile.js
================================================
const gulp = require('gulp');
const copyfiles = require('copyfiles');
const LIBRARY_SRC = '../dist/**/*';
const LIBRARY_DIST = 'esm/lib';
gulp.task('copy-lib', (callback) => {
copyfiles([ LIBRARY_SRC, LIBRARY_DIST ], 2, callback);
});
gulp.task('copy-lib:watch', () => {
gulp.watch(LIBRARY_SRC, ['copy-lib']);
});
================================================
FILE: demo/package.json
================================================
{
"name": "angular-library-seed-demo",
"description": "AOT/JIT/UMD build demo of angular library seed",
"license": "MIT",
"scripts": {
"build": "npm run build:aot && npm run build:jit && npm run build:umd",
"build:aot": "npm run build:aot:compile && npm run build:aot:bundle",
"build:aot:bundle": "webpack --config esm/webpack-aot.config.js --bail",
"build:aot:compile": "node_modules/.bin/ngc -p esm/tsconfig-aot.json",
"build:jit": "webpack --config esm/webpack.config.js --bail",
"build:umd": "npm run clean:umd && copyfiles --up 2 \"../dist/index.umd.*\" umd/lib",
"clean:all": "npm run clean:tmp && rimraf node_modules",
"clean:tmp": "npm run clean:esm:aot && npm run clean:esm:jit && npm run clean:umd && rimraf esm/dist",
"clean:esm:aot": "npm run clean:esm:tmp && rimraf esm/dist/aot",
"clean:esm:jit": "npm run clean:esm:tmp && rimraf esm/dist/jit",
"clean:esm:tmp": "rimraf esm/lib esm/node_modules esm/src/app/*.ngfactory.ts esm/src/app/*.ngsummary.json",
"clean:umd": "rimraf umd/lib",
"copy-lib": "copyfiles --up 2 \"../dist/**/*\" esm/lib",
"prebuild:aot": "npm run clean:esm:aot && npm run copy-lib",
"prebuild:jit": "npm run clean:esm:jit && npm run copy-lib",
"prestart": "npm run clean:esm:jit && npm run copy-lib",
"start": "concurrently --raw \"gulp copy-lib:watch\" \"webpack-dev-server --open --watch --config esm/webpack.config.js\""
},
"dependencies": {
"@angular/common": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0"
},
"devDependencies": {
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"awesome-typescript-loader": "^3.1.2",
"concurrently": "^3.4.0",
"copyfiles": "^1.2.0",
"core-js": "^2.4.1",
"gulp": "^3.9.1",
"html-webpack-plugin": "^2.8.1",
"rimraf": "^2.6.1",
"rxjs": "^5.2.0",
"typescript": "^2.2.0",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.4.5",
"zone.js": "^0.8.4"
}
}
================================================
FILE: demo/umd/app/app.component.ts
================================================
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: ``
})
export class AppComponent {
public header: string = 'UMD Demo';
}
================================================
FILE: demo/umd/app/app.module.ts
================================================
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { TickTockModule } from 'ticktock';
@NgModule({
imports: [ BrowserModule, TickTockModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
================================================
FILE: demo/umd/index.html
================================================
Loading...
================================================
FILE: demo/umd/main.ts
================================================
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
================================================
FILE: demo/umd/systemjs.config.js
================================================
(function (global) {
System.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER.
transpiler: 'ts',
typescriptOptions: {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
meta: {
"typescript": {
"exports": "ts"
}
},
paths: {
'npm:': 'https://unpkg.com/'
},
map: {
// Our app is within the app folder.
'app': 'app',
// Angular bundles.
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
// Third party libraries.
'rxjs': 'npm:rxjs@5.0.1',
'ts': 'npm:plugin-typescript@5.2.7/lib/plugin.js',
'typescript': 'npm:typescript@2.2.1/lib/typescript.js',
'ticktock': 'lib/index.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: 'main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
ticktock: {
defaultExtension: 'js'
}
}
});
})(this);
================================================
FILE: gulpfile.js
================================================
const gulp = require('gulp');
const sass = require('node-sass');
const inlineTemplates = require('gulp-inline-ng2-template');
const exec = require('child_process').exec;
/**
* Inline templates configuration.
* @see https://github.com/ludohenin/gulp-inline-ng2-template
*/
const INLINE_TEMPLATES = {
SRC: './src/**/*.ts',
DIST: './tmp/src-inlined',
CONFIG: {
base: '/src',
target: 'es6',
useRelativePaths: true,
styleProcessor: compileSass
}
};
/**
* Inline external HTML and SCSS templates into Angular component files.
* @see: https://github.com/ludohenin/gulp-inline-ng2-template
*/
gulp.task('inline-templates', () => {
return gulp.src(INLINE_TEMPLATES.SRC)
.pipe(inlineTemplates(INLINE_TEMPLATES.CONFIG))
.pipe(gulp.dest(INLINE_TEMPLATES.DIST));
});
/**
* Build ESM by running npm task.
* This is a temporary solution until ngc is supported --watch mode.
* @see: https://github.com/angular/angular/issues/12867
*/
gulp.task('build:esm', ['inline-templates'], (callback) => {
exec('npm run ngcompile', function (error, stdout, stderr) {
console.log(stdout, stderr);
callback(error)
});
});
/**
* Implements ESM build watch mode.
* This is a temporary solution until ngc is supported --watch mode.
* @see: https://github.com/angular/angular/issues/12867
*/
gulp.task('build:esm:watch', ['build:esm'], () => {
gulp.watch('src/**/*', ['build:esm']);
});
/**
* Compile SASS to CSS.
* @see https://github.com/ludohenin/gulp-inline-ng2-template
* @see https://github.com/sass/node-sass
*/
function compileSass(path, ext, file, callback) {
let compiledCss = sass.renderSync({
file: path,
outputStyle: 'compressed',
});
callback(null, compiledCss.css);
}
================================================
FILE: karma-test-entry.ts
================================================
import 'core-js';
import 'rxjs/Rx';
import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/proxy';
import 'zone.js/dist/jasmine-patch';
import { TestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
const testsContext: any = require.context('./src', true, /\.spec/);
testsContext.keys().forEach(testsContext);
================================================
FILE: karma.conf.ts
================================================
import webpackTestConfig from './webpack-test.config';
import { ConfigOptions } from 'karma';
export default (config) => {
config.set({
// Base path that will be used to resolve all patterns (eg. files, exclude).
basePath: './',
// Frameworks to use.
// Available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// List of files to load in the browser.
files: [
'karma-test-entry.ts'
],
// Preprocess matching files before serving them to the browser.
// Available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'karma-test-entry.ts': ['webpack', 'sourcemap']
},
webpack: webpackTestConfig,
// Webpack please don't spam the console when running in karma!
webpackMiddleware: {
noInfo: true,
// Use stats to turn off verbose output.
stats: {
chunks: false
}
},
mime: {
'text/x-typescript': [ 'ts' ]
},
coverageIstanbulReporter: {
reports: ['text-summary', 'html', 'lcovonly'],
fixWebpackSourcePaths: true
},
// Test results reporter to use.
// Possible values: 'dots', 'progress'.
// Available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage-istanbul'],
// Level of logging
// Possible values:
// - config.LOG_DISABLE
// - config.LOG_ERROR
// - config.LOG_WARN
// - config.LOG_INFO
// - config.LOG_DEBUG
logLevel: config.LOG_WARN,
// Start these browsers.
// Available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
browserConsoleLogOptions: {
terminal: true,
level: 'log'
},
singleRun: true,
colors: true
} as ConfigOptions);
};
================================================
FILE: package.json
================================================
{
"name": "angular-library-seed",
"version": "0.0.20",
"description": "Angular library seed",
"main": "./dist/index.umd.js",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts",
"license": "MIT",
"keywords": [
"angular",
"angular4",
"aot",
"aot-compatible",
"aot-compilation",
"library",
"ng",
"seed",
"starter",
"tick-tock",
"typescript"
],
"author": {
"name": "Oleksii Trekhleb",
"url": "https://www.linkedin.com/in/trekhleb/"
},
"repository": {
"type": "git",
"url": "https://github.com/trekhleb/angular-library-seed.git"
},
"bugs": {
"url": "https://github.com/trekhleb/angular-library-seed/issues"
},
"homepage": "https://github.com/trekhleb/angular-library-seed#readme",
"scripts": {
"build": "npm run build:esm && npm run build:umd",
"build:esm": "gulp inline-templates && npm run ngcompile",
"build:esm:watch": "gulp build:esm:watch",
"build:umd": "webpack --config webpack-umd.config.ts",
"build:umd:watch": "npm run build:umd -- --watch",
"build:watch": "concurrently --raw \"npm run build:umd:watch\" \"npm run build:esm:watch\"",
"ci": "npm run lint && npm run test && npm run build && npm run docs",
"clean:all": "npm run clean:tmp && rimraf node_modules",
"clean:tmp": "rimraf coverage dist tmp docs",
"codecov": "cat coverage/lcov.info | codecov",
"docs": "compodoc -p tsconfig.json -d docs --disableCoverage --disablePrivateOrInternalSupport",
"explorer": "source-map-explorer ./dist/index.umd.js",
"gh-pages": "rimraf docs && npm run docs && gh-pages -d docs",
"lint": "npm run tslint 'src/**/*.ts'",
"ngcompile": "node_modules/.bin/ngc -p tsconfig-aot.json",
"postversion": "git push && git push --tags",
"prebuild": "rimraf dist tmp",
"prebuild:watch": "rimraf dist tmp",
"prepublishOnly": "npm run ci",
"preversion": "npm run ci",
"test": "karma start",
"test:watch": "karma start --auto-watch --no-single-run",
"tslint": "tslint"
},
"dependencies": {},
"peerDependencies": {
"@angular/common": "^4.0.0",
"@angular/core": "^4.0.0"
},
"devDependencies": {
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@compodoc/compodoc": "^1.0.0-beta.9",
"@types/jasmine": "^2.5.47",
"@types/karma": "^1.7.0",
"@types/node": "^8.0.0",
"@types/webpack": "^3.0.13",
"@types/webpack-env": "^1.13.0",
"angular2-template-loader": "^0.6.2",
"awesome-typescript-loader": "^3.1.3",
"codecov": "^2.2.0",
"codelyzer": "^3.0.1",
"concurrently": "^3.4.0",
"css-loader": "^0.28.1",
"gh-pages": "^1.0.0",
"gulp": "^3.9.1",
"gulp-inline-ng2-template": "^4.0.0",
"istanbul-instrumenter-loader": "^3.0.0",
"jasmine-core": "^2.6.1",
"json-loader": "^0.5.4",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.1.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.3",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.3",
"node-sass": "^4.5.2",
"raw-loader": "^0.5.1",
"rimraf": "^2.6.1",
"rxjs": "^5.3.1",
"sass-loader": "^6.0.5",
"source-map-explorer": "^1.3.3",
"to-string-loader": "^1.1.5",
"ts-node": "^3.0.4",
"tslint": "^5.2.0",
"typescript": "^2.3.2",
"webpack": "^3.6.0",
"webpack-angular-externals": "^1.0.2",
"webpack-rxjs-externals": "^1.0.0",
"zone.js": "^0.8.10"
}
}
================================================
FILE: src/components/index.ts
================================================
export * from './tick-tock';
================================================
FILE: src/components/tick-tock/index.ts
================================================
export * from './tick-tock.component';
================================================
FILE: src/components/tick-tock/tick-tock.component.html
================================================
{{ currentTime }}
================================================
FILE: src/components/tick-tock/tick-tock.component.scss
================================================
@import url('https://fonts.googleapis.com/css?family=Roboto:100');
// Timer styles.
.tick-tock-time {
font-size: 2em;
font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
================================================
FILE: src/components/tick-tock/tick-tock.component.spec.ts
================================================
import {
async,
ComponentFixture,
TestBed
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { TickTockModule } from '../../';
import { TickTockComponent } from './tick-tock.component';
describe('TickTockComponent', () => {
const timeStringFormat = /[0-9]{2}:[0-9]{2}:[0-9]{2}/i;
let componentFixture: ComponentFixture;
let componentInstance: TickTockComponent;
// Asynchronous beforeEach.
beforeEach(
async(() => {
TestBed.configureTestingModule({
imports: [ TickTockModule ]
}).compileComponents().then(() => { /* Don't do anything */ });
})
);
// Synchronous BeforeEach.
beforeEach(() => {
componentFixture = TestBed.createComponent(TickTockComponent);
componentInstance = componentFixture.componentInstance;
});
it('should display time string', (done) => {
componentFixture.detectChanges();
setInterval(() => {
componentFixture.detectChanges();
const tickTockPageElement = componentFixture.debugElement.queryAll(By.css('.tick-tock-time'));
const displayedTimeText = tickTockPageElement[0].nativeElement.innerText;
expect(tickTockPageElement).toBeDefined();
expect(tickTockPageElement.length).toEqual(1);
expect(displayedTimeText.length).toEqual(8);
expect(timeStringFormat.test(displayedTimeText)).toBeTruthy();
done();
}, 1000);
});
});
================================================
FILE: src/components/tick-tock/tick-tock.component.ts
================================================
import { Component, OnInit } from '@angular/core';
import { TickTockService } from '../../services';
@Component({
selector: 'tick-tock',
styleUrls: ['./tick-tock.component.scss'],
templateUrl: './tick-tock.component.html',
})
export class TickTockComponent implements OnInit {
// Current time string.
public currentTime: string;
/**
* Component constructor with injected dependencies.
* @param tickTockService
*/
public constructor(
private tickTockService: TickTockService
) {}
/**
* Implements onInit event handler.
*/
public ngOnInit(): void {
this.tickTockService.getTick().subscribe(
(timeString) => this.currentTime = timeString
);
}
}
================================================
FILE: src/index.ts
================================================
export { TickTockService } from './services';
export { TickTockComponent } from './components';
export { TickTockModule } from './tick-tock.module';
================================================
FILE: src/services/index.ts
================================================
export * from './tick-tock';
================================================
FILE: src/services/tick-tock/index.ts
================================================
export * from './tick-tock.service';
================================================
FILE: src/services/tick-tock/tick-tock.service.spec.ts
================================================
import { TickTockService } from './tick-tock.service';
describe('TickTockService', () => {
let tickTockService: TickTockService;
beforeEach(() => {
tickTockService = new TickTockService();
});
it('should return observable with time string', (done) => {
const timeStringFormat = /[0-9]{2}:[0-9]{2}:[0-9]{2}/i;
tickTockService.getTick().subscribe(
(timeString) => {
expect(timeStringFormat.test(timeString)).toBeTruthy(
'Time string should have hh:mm:ss format'
);
// Stop asynchronous test.
done();
}
);
});
});
================================================
FILE: src/services/tick-tock/tick-tock.service.ts
================================================
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
/**
* TickTockService class.
*/
@Injectable()
export class TickTockService {
/**
* Extend time value with zero if required.
* @param value
* @returns {string}
*/
private static formatTimeNumber(value: number): string {
const stringValue = value.toString();
return ('0' + stringValue).slice(-2);
}
/**
* Get current time string.
* @returns {string}
*/
private static getNowString(): string {
const date = new Date();
const hours = TickTockService.formatTimeNumber(date.getHours());
const minutes = TickTockService.formatTimeNumber(date.getMinutes());
const seconds = TickTockService.formatTimeNumber(date.getSeconds());
return `${hours}:${minutes}:${seconds}`;
}
/**
* Set up timer frequency.
* @type {number}
*/
private readonly TIMEOUT: number = 1000;
/**
* Get current time observable.
* @returns Observable
*/
public getTick(): Observable {
return Observable
.timer(0, this.TIMEOUT)
.map((tick) => TickTockService.getNowString());
}
}
================================================
FILE: src/tick-tock.module.ts
================================================
import { NgModule } from '@angular/core';
import { TickTockComponent } from './components';
import { TickTockService } from './services';
@NgModule({
providers: [
TickTockService,
],
declarations: [
TickTockComponent,
],
exports: [
TickTockComponent,
]
})
export class TickTockModule {
}
================================================
FILE: tsconfig-aot.json
================================================
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"removeComments": false,
"noImplicitAny": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"pretty": true,
"stripInternal": true,
"skipLibCheck": true,
"outDir": "dist",
"rootDir": "./tmp/src-inlined"
},
"files": [
"./tmp/src-inlined/index.ts"
],
"angularCompilerOptions": {
"genDir": "dist",
"debug": false,
"skipTemplateCodegen": true,
"skipMetadataEmit": false,
"strictMetadataEmit": true
}
}
================================================
FILE: tsconfig.json
================================================
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
"sourceMap": true,
"declaration": false,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": [
"es2015",
"dom"
],
"typeRoots" : [
"./node_modules/@types"
],
"types": [
"jasmine",
"karma",
"node",
"webpack",
"webpack-env"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.spec.ts",
"node_modules",
"demo",
"dist"
]
}
================================================
FILE: tslint.json
================================================
{
"extends": ["tslint:recommended"],
"rulesDirectory": ["node_modules/codelyzer"],
"rules": {
"component-class-suffix": true,
"directive-class-suffix": true,
"interface-name": false,
"invoke-injectable": true,
"max-line-length": [true, 100],
"no-access-missing-member": false,
"no-attribute-parameter-decorator": true,
"no-console": [true, "time", "timeEnd", "trace"],
"no-forward-ref": true,
"no-input-rename": true,
"no-output-rename": true,
"no-string-literal": false,
"object-literal-sort-keys": false,
"ordered-imports": false,
"pipe-naming": [true, "camelCase", "my"],
"quotemark": [true, "single", "avoid-escape"],
"trailing-comma": [false, {"multiline": "always", "singleline": "never"}],
"use-host-property-decorator": true,
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-pipe-transform-interface": true,
"variable-name": [true, "allow-leading-underscore", "ban-keywords", "check-format"]
}
}
================================================
FILE: webpack-test.config.ts
================================================
import * as webpack from 'webpack';
import * as path from 'path';
export default {
resolve: {
extensions: [ '.ts', '.js', '.json' ]
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: 'tsconfig.json'
}
},
{
loader: 'angular2-template-loader'
}
],
exclude: [
/\.e2e\.ts$/,
/node_modules/
]
},
{
test: /.ts$/,
exclude: /(node_modules|\.spec\.ts|\.e2e\.ts$)/,
loader: 'istanbul-instrumenter-loader',
enforce: 'post'
},
{
test: /\.json$/,
use: 'json-loader'
},
{
test: /\.css$/,
use: ['to-string-loader', 'css-loader']
},
{
test: /\.scss$/,
use: ['to-string-loader', 'css-loader', 'sass-loader']
},
{
test: /\.html$/,
use: 'raw-loader'
}
]
},
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: null,
test: /\.(ts|js)($|\?)/i
}),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
path.join(__dirname, 'src')
),
new webpack.NoEmitOnErrorsPlugin()
]
} as webpack.Configuration;
================================================
FILE: webpack-umd.config.ts
================================================
import * as webpack from 'webpack';
import * as path from 'path';
import * as fs from 'fs';
import * as angularExternals from 'webpack-angular-externals';
import * as rxjsExternals from 'webpack-rxjs-externals';
const pkg = JSON.parse(fs.readFileSync('./package.json').toString());
export default {
entry: {
'index.umd': './src/index.ts',
'index.umd.min': './src/index.ts',
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'umd',
library: 'ticktock'
},
resolve: {
extensions: [ '.ts', '.js', '.json' ]
},
externals: [
angularExternals(),
rxjsExternals()
],
devtool: 'source-map',
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: 'tsconfig.json'
}
},
{
loader: 'angular2-template-loader'
}
],
exclude: [
/node_modules/,
/\.(spec|e2e)\.ts$/
]
},
{
test: /\.json$/,
use: 'json-loader'
},
{
test: /\.css$/,
use: ['to-string-loader', 'css-loader']
},
{
test: /\.scss$/,
use: ['to-string-loader', 'css-loader', 'sass-loader']
},
{
test: /\.html$/,
use: 'raw-loader'
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
path.join(__dirname, 'src')
),
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
sourceMap: true
}),
new webpack.BannerPlugin({
banner: `
/**
* ${pkg.name} - ${pkg.description}
* @version v${pkg.version}
* @author ${pkg.author.name}
* @link ${pkg.homepage}
* @license ${pkg.license}
*/
`.trim(),
raw: true,
entryOnly: true
})
]
} as webpack.Configuration;