A simple plunker demonstrating Angular2 usage:
- Uses SystemJS + TypeScript to compile on the fly
- Includes binding, directives, http, pipes, and DI usage.
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function { | |
var zone = this.manager.getZone(); | |
var eventsArray = this.getMultiEventArray(eventName); | |
// Entering back into angular to trigger changeDetection | |
var outsideHandler = (event) => { | |
zone.run(() => handler(event)) | |
}; | |
// Executed outside of angular so that change detection is not constantly triggered. |
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function { | |
var zone = this.manager.getZone(); | |
var eventsArray = this.getMultiEventArray(eventName); | |
// Entering back into angular to trigger changeDetection | |
var outsideHandler = (event) => { | |
zone.run(() => handler(event)) | |
}; | |
// Executed outside of angular so that change detection is not constantly triggered. |
import {provide, PLATFORM_DIRECTIVES, PLATFORM_PIPES} from '@angular/core'; | |
import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router'; | |
import {FORM_PROVIDERS} from '@angular/common'; | |
import {HTTP_PROVIDERS, JSONP_PROVIDERS} from '@angular/http'; | |
import {ELEMENT_PROBE_PROVIDERS /*,ELEMENT_PROBE_PROVIDERS_PROD_MODE*/} from '@angular/platform-browser'; | |
import {LocationStrategy, HashLocationStrategy, Location} from '@angular/common'; | |
/* | |
Add custom env providers here. |
When you use the names
property in the CommonsChunkPlugin({})
and pass an array as the value, webpack converts what is seen below:
new webpack.optimize.CommonsChunkPlugin({
names: ['app', 'vendor', 'manifest'], // creating manifest.js
minChunks: Infinity
})
Into:
module.exports = config; | |
const config = { | |
module: { | |
rules: [ //<=== 'loaders' works as a fallback but for .23+ best to start using "rules" instead. | |
{ | |
test: /\.less/, | |
loaders: [ | |
"style-loader", | |
{loader: "css-loader", query: {}}, |
const MODULE_DIR = /(.*([\/\\]node_modules|\.\.)[\/\\](@[^\/\\]+[\/\\])?[^\/\\]+)([\/\\].*)?$/g; | |
{ | |
loader: 'babel-loader', | |
test: /\.jsx?$/, | |
include(filepath) { | |
if (filepath.split(/[/\\]/).indexOf('node_modules')===-1) return true; | |
let pkg, manifest = path.resolve(filepath.replace(MODULE_DIR, '$1'), 'package.json'); | |
try { pkg = JSON.parse(fs.readFileSync(manifest)); } catch (e) {} | |
return !!(pkg.modules || pkg['jsnext:main']); |
const createClass = () => { | |
return class { | |
constructor(options) { this.options = options || {}; } | |
}; | |
} | |
const Plugin = (x) => ( | |
return { | |
map: f => Plugin(f(x)), |
import(/* webpackChunkName: "my-chunk-name" */ 'module'); |
import("./abc.js").then(abc => abc.doIt()); |