From 393674c06417e63a2ff4dcfb3a529aa8df173dd7 Mon Sep 17 00:00:00 2001 From: Dmitriy Shekhovtsov Date: Wed, 20 Apr 2016 18:17:21 +0300 Subject: [PATCH] feat(package): updated to angular2 beta.15 fixes #106 updated build and publish flow --- .config/bundle-system.js | 103 +++++++++++++++++++ .eslintrc | 200 ------------------------------------ .eslintrc.json | 6 ++ .gitignore | 9 +- .npmignore | 21 +++- LICENSE | 4 +- README.md | 7 +- components/select/select.ts | 2 +- demo/index.html | 10 +- demo/index.ts | 2 +- gulp-tasks/lint.js | 34 +++--- gulpfile.js | 19 +--- ng2-select.ts | 8 ++ package.json | 74 +++++++++---- tsconfig.json | 7 +- tslint.json | 56 +--------- typings.json | 11 ++ webpack.config.js | 140 +++++++++++++------------ 18 files changed, 318 insertions(+), 395 deletions(-) create mode 100755 .config/bundle-system.js delete mode 100644 .eslintrc create mode 100644 .eslintrc.json create mode 100644 typings.json diff --git a/.config/bundle-system.js b/.config/bundle-system.js new file mode 100755 index 00000000..1894fa21 --- /dev/null +++ b/.config/bundle-system.js @@ -0,0 +1,103 @@ +#!/usr/bin/env node +'use strict'; + +/*eslint no-console: 0, no-sync: 0*/ + +// System.js bundler +// simple and yet reusable system.js bundler +// bundles, minifies and gzips + +const fs = require('fs'); +const del = require('del'); +const path = require('path'); +const zlib = require('zlib'); +const async = require('async'); +const Builder = require('systemjs-builder'); + +const pkg = require('../package.json'); +const name = pkg.name; +const targetFolder = path.resolve('./bundles'); +console.log(targetFolder) +async.waterfall([ + cleanBundlesFolder, + getSystemJsBundleConfig, + buildSystemJs({minify: false, sourceMaps: true, mangle: false}), + getSystemJsBundleConfig, + buildSystemJs({minify: true, sourceMaps: true, mangle: false}), + gzipSystemJsBundle +], err => { + if (err) { + throw err; + } +}); + +function getSystemJsBundleConfig(cb) { + const config = { + baseURL: '..', + transpiler: 'typescript', + typescriptOptions: { + module: 'cjs' + }, + map: { + typescript: path.resolve('node_modules/typescript/lib/typescript.js'), + angular2: path.resolve('node_modules/angular2'), + rxjs: path.resolve('node_modules/rxjs') + }, + paths: { + '*': '*.js' + } + }; + + config.meta = ['angular2', 'rxjs'].reduce((memo, currentValue) => { + memo[path.resolve(`node_modules/${currentValue}/*`)] = {build: false}; + return memo; + }, {}); + config.meta.moment = {build: false}; + console.log(config.meta) + return cb(null, config); +} + +function cleanBundlesFolder(cb) { + return del(targetFolder) + .then(paths => { + console.log('Deleted files and folders:\n', paths.join('\n')); + cb(); + }); +} + +function buildSystemJs(options) { + return (config, cb) => { + const minPostFix = options && options.minify ? '.min' : ''; + const fileName = `${name}${minPostFix}.js`; + const dest = path.resolve(__dirname, targetFolder, fileName); + const builder = new Builder(); + + console.log('Bundling system.js file:', fileName, options); + builder.config(config); + return builder + .bundle([name, name].join('/'), dest, options) + .then(() => cb()) + .catch(cb); + }; +} + +function gzipSystemJsBundle(cb) { + const files = fs + .readdirSync(path.resolve(targetFolder)) + .map(file => path.resolve(targetFolder, file)) + .filter(file => fs.statSync(file).isFile()) + .filter(file => path.extname(file) !== 'gz'); + + return async.eachSeries(files, (file, gzipcb) => { + process.nextTick(() => { + console.log('Gzipping ', file); + const gzip = zlib.createGzip({level: 9}); + const inp = fs.createReadStream(file); + const out = fs.createWriteStream(`${file}.gz`); + + inp.on('end', () => gzipcb()); + inp.on('error', err => gzipcb(err)); + return inp.pipe(gzip).pipe(out); + }); + }, cb); +} diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 1025ddc1..00000000 --- a/.eslintrc +++ /dev/null @@ -1,200 +0,0 @@ -{ - "env": { - "browser": 2, - "node": 2, - "mocha": 2, - "es6": 2 - }, - "ecmaFeatures": { - "modules": true - }, - "globals": { - "_": 2, - "$": 2, - "angular": 2, - "jQuery": 2 - }, - "rules": { - // Possible Errors - "comma-dangle": 2, - // no-comma-dangle - (deprecated) - "no-cond-assign": [2, "always"], - "no-console": 2, - "no-constant-condition": 2, - "no-control-regex": 2, - "no-debugger": 2, - "no-dupe-keys": 2, - "no-dupe-args": 2, - "no-duplicate-case": 2, - "no-empty-character-class": 2, - // no-empty-class - (deprecated) - "no-empty": 2, - "no-ex-assign": 2, - "no-extra-boolean-cast": 2, - "no-extra-parens": 2, - "no-extra-semi": 2, - "no-func-assign": 2, - "no-inner-declarations": 2, - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-negated-in-lhs": 2, - "no-obj-calls": 2, - "no-regex-spaces": 2, - "no-sparse-arrays": 2, - "no-unreachable": 2, - "use-isnan": 2, - "valid-jsdoc": 2, - "valid-typeof": 2, - "no-unexpected-multiline": 2, - - // Best Practices - // not sure - "accessor-pairs": [2, {"getWithoutSet": false, "setWithoutGet": true}], - "block-scoped-var": 2, - "complexity": [2, 6], - "consistent-return": 2, - "curly": 2, - "default-case": 2, - "dot-notation": 2, - // not good for chain calls, but not for properties - "dot-location": [2, "property"], - "eqeqeq": 2, - "guard-for-in": 2, - "no-alert": 2, - "no-caller": 2, - "no-div-regex": 2, - "no-else-return": 2, - "no-empty-label": 2, - "no-eq-null": 2, - "no-eval": 2, - "no-extend-native": 2, - "no-extra-bind": 2, - "no-fallthrough": 2, - "no-floating-decimal": 2, - "no-implied-eval": 2, - "no-iterator": 2, - "no-labels": 2, - "no-lone-blocks": 2, - "no-loop-func": 2, - "no-multi-spaces": 2, - "no-multi-str": 2, - "no-native-reassign": 2, - "no-new": 2, - "no-new-func": 2, - "no-new-wrappers": 2, - "no-octal": 2, - "no-octal-escape": 2, - "no-param-reassign": 2, - "no-process-env": 2, - "no-proto": 2, - "no-redeclare": 2, - "no-return-assign": 2, - "no-script-url": 2, - "no-self-compare": 2, - "no-sequences": 2, - "no-throw-literal": 2, - "no-unused-expressions": 2, - "no-void": 2, - "no-warning-comments": [1, { "terms": ["todo", "fixme"], "location": "anywhere" }], - "no-with": 2, - "radix": 2, - "vars-on-top": 0, - "wrap-iife": [2, "inside"], - "yoda": [2, "never"], - - // Strict Mode - "strict": [2, "global"], - - // Variables - "no-catch-shadow": 2, - "no-delete-var": 2, - "no-label-var": 2, - "no-shadow": 2, - "no-shadow-restricted-names": 2, - "no-undef": 2, - "no-undef-init": 2, - "no-undefined": 2, - "no-unused-vars": 2, - "no-use-before-define": [2, "nofunc"], - - // Node.js - "handle-callback-err": [2, "^.*(e|E)rr" ], - "no-mixed-requires": [2, true], - "no-new-require": 2, - "no-path-concat": 2, - "no-process-exit": 2, - "no-sync": 2, - - // Stylistic Issues - "array-bracket-spacing": [2, "never"], - "brace-style": [2, "1tbs", { "allowSingleLine": true }], - "camelcase": 2, - "comma-spacing": [2, {"before": false, "after": true}], - "comma-style": [2, "last"], - "computed-property-spacing": [2, "never"], - "consistent-this": [2, "self"], - // not sure - "eol-last": 0, - "func-names": 0, - "func-style": [2, "declaration"], - "indent": [2, 2], - "key-spacing": [2, { "beforeColon": false, "afterColon": true}], - "max-nested-callbacks": [2, 3], - "new-cap": [2, {"newIsCap": true, "capIsNew": true, "capIsNewExceptions":[ - "ObjectId", - "Object", - "Function", - "Number", - "String", - "Boolean", - "Date", - "Array", - "Symbol", - "RegExp" - ]}], - "new-parens": 2, - "newline-after-var": 0, - "no-array-constructor": 2, - "no-inline-comments": 2, - "no-lonely-if": 2, - "no-mixed-spaces-and-tabs": 2, - "no-multiple-empty-lines": [2, {"max": 1}], - "no-nested-ternary": 2, - "no-new-object": 2, - "no-spaced-func": 2, - "no-ternary": 0, - "no-trailing-spaces": 2, - "no-underscore-dangle": 2, - "no-unneeded-ternary": 2, - "object-curly-spacing": [2, "never"], - "one-var": [2, { - "var": "never", // Exactly one var declaration per function - "let": "never", // Exactly one let declaration per block - "const": "never" // Exactly one declarator per const declaration per block - }], - "operator-assignment": [1, "always"], - "operator-linebreak": [2, "after"], - "padded-blocks": [2, "never"], - "quote-props": [2, "as-needed"], - "quotes": [2, "single", "avoid-escape"], - "semi": [2, "always"], - "semi-spacing": 2, - // "sort-vars": [1, { "ignoreCase": true }], - "space-after-keywords": [2, "always" ], - "space-before-blocks": [2, "always"], - "space-in-parens": [2, "never"], - "space-infix-ops": 2, - "space-return-throw-case": 2, - "space-unary-ops": [2, { "words": true, "nonwords": false }], - "spaced-comment": 0, - "wrap-regexp": 0, - - // Legacy - "max-len": [1, 120, 4], - // todo: apply max-params - "max-params": [0, 3], - // todo: apply max-statements - "max-statements": [2, 30], - "no-bitwise": 2 - } -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..f8afe993 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "extends": "./node_modules/eslint-config-valorsoft/.eslintrc.json", + "env": { + "node": true + } +} diff --git a/.gitignore b/.gitignore index f68b09fb..faf02f93 100644 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,18 @@ /node_modules npm-debug.log +# type script artifacts +/typings + # WebStorm .idea # ignore build and dist for now -/build +/bundles +/demo-build +/dist +/coverage +/ts /demo/**/*.js diff --git a/.npmignore b/.npmignore index f4ba59a3..8f189f28 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,24 @@ .idea -demo -build gulp-tasks logs +# typings +typings + +# testing +karma.conf.js +test.bundle.js +coverage + +# demo build +demo +demo-build webpack.config.js + +#typescript sources +*.ts +*.js.map +!*.d.ts +/components/**/*.ts +!/components/**/*.d.ts + diff --git a/LICENSE b/LICENSE index bf4dedb9..901dcb19 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2015 Dmitriy Shekhovtsov -Copyright (c) 2015 Valor Software +Copyright (c) 2015-2016 Dmitriy Shekhovtsov +Copyright (c) 2015-2016 Valor Software Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 39db7e7c..44b82262 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,16 @@ -# ng2-select [![npm version](https://badge.fury.io/js/ng2-select.svg)](http://badge.fury.io/js/ng2-select) [![npm downloads](https://img.shields.io/npm/dm/ng2-select.svg)](https://npmjs.org/ng2-select) +# Native UI Select Angular2 component ([demo](http://valor-software.com/ng2-select/)) +## ng2-select [![npm version](https://badge.fury.io/js/ng2-select.svg)](http://badge.fury.io/js/ng2-select) [![npm downloads](https://img.shields.io/npm/dm/ng2-select.svg)](https://npmjs.org/ng2-select) Follow me at [twitter](https://twitter.com/valorkin) to be notified about new releases. +[![Angular 2 Style Guide](https://mgechev.github.io/angular2-style-guide/images/badge.svg)](https://github.com/mgechev/angular2-style-guide) [![Code Climate](https://codeclimate.com/github/valor-software/ng2-select/badges/gpa.svg)](https://codeclimate.com/github/valor-software/ng2-select) +[![Build Status](https://travis-ci.org/valor-software/ng2-select.svg?branch=master)](https://travis-ci.org/valor-software/ng2-select) [![Join the chat at https://gitter.im/valor-software/ng2-bootstrap](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/valor-software/ng2-bootstrap?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![devDependency Status](https://david-dm.org/valor-software/ng2-select/dev-status.svg)](https://david-dm.org/valor-software/ng2-select#info=devDependencies) [![Throughput Graph](https://graphs.waffle.io/valor-software/ng2-select/throughput.svg)](https://waffle.io/valor-software/ng2-select/metrics) -Native Select Angular2 component + ## Quick start diff --git a/components/select/select.ts b/components/select/select.ts index 055b9209..005e240b 100644 --- a/components/select/select.ts +++ b/components/select/select.ts @@ -262,7 +262,7 @@ export class Select { return; } - if (srcElement.contains(context.element.nativeElement) + if (e.srcElement.contains(context.element.nativeElement) && e.srcElement && e.srcElement.className && e.srcElement.className.indexOf('ui-select') >= 0) { if (e.target.nodeName !== 'INPUT') { diff --git a/demo/index.html b/demo/index.html index a23d853f..266abc2b 100644 --- a/demo/index.html +++ b/demo/index.html @@ -9,11 +9,11 @@ - + - + @@ -35,11 +35,5 @@ Loading... - - - - - - diff --git a/demo/index.ts b/demo/index.ts index 8ba7f05f..0c7142af 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -1,4 +1,4 @@ -import {bootstrap} from 'angular2/bootstrap'; +import {bootstrap} from 'angular2/platform/browser'; import {Component} from 'angular2/core'; import {NgClass} from 'angular2/common'; diff --git a/gulp-tasks/lint.js b/gulp-tasks/lint.js index 1371ed52..8d7e794b 100644 --- a/gulp-tasks/lint.js +++ b/gulp-tasks/lint.js @@ -1,23 +1,19 @@ -var gulp = require('gulp'); -var esLint = require('gulp-eslint'); -var tslint = require('gulp-tslint'); +'use strict'; -var paths = gulp.paths; +const gulp = require('gulp'); +const tslint = require('gulp-tslint'); +const paths = gulp.paths; +const tslintConf = require('../tslint.json'); -gulp.task('eslint', function() { - return gulp.src(paths.jssrc) - .pipe(esLint({useEslintrc: true})) - .pipe(esLint.format()) - .pipe(esLint.failOnError()); -}); - -gulp.task('tslint', function() { - return gulp.src(paths.tssrc) - .pipe(tslint()) - .pipe(tslint.report('verbose', { +gulp.task('tslint', () => + gulp + .src(paths.tssrc) + .pipe(tslint(tslintConf)) + .pipe(tslint.report('prose', { emitError: true, - reportLimit: 0 - })); -}); + summarizeFailureOutput: true, + reportLimit: 50 + })) +); -gulp.task('lint', ['tslint', 'eslint']); +gulp.task('lint', ['tslint']); diff --git a/gulpfile.js b/gulpfile.js index 8d2c6b20..c56b8414 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,27 +3,14 @@ var gulp = require('gulp'); gulp.paths = { tssrc: [ '**/*.ts', + '!**/*.d.ts', '!node_modules/**/*', - '!dist/**/*', - '!typings/**/*', - '!**/*.{ts,coffee}.js'], - jssrc: [ - '*.js', - 'gulp-tasks/*.js', - '!ng2-select.js', - '!angular2-select.js', - '!node_modules', - '!**/*.{ts,coffee}.js'] + '!bundles/**/*', + '!typings/**/*'] }; require('require-dir')('./gulp-tasks'); -var clean = require('gulp-clean'); -gulp.task('clean', function () { - return gulp.src('dist', {read: false}) - .pipe(clean()); -}); - gulp.task('default', function () { gulp.start('lint'); }); diff --git a/ng2-select.ts b/ng2-select.ts index d45452f7..21216aff 100644 --- a/ng2-select.ts +++ b/ng2-select.ts @@ -1,2 +1,10 @@ +import {SELECT_DIRECTIVES} from './components/select'; + export * from './components/select/select'; export * from './components/select'; + +export default { + directives: [ + SELECT_DIRECTIVES + ] +} diff --git a/package.json b/package.json index 887ea4dc..45d399a0 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,29 @@ "version": "1.0.1-beta.0", "description": "Angular2 based replacement for select boxes", "scripts": { - "deploy": "NODE_ENV=production webpack -p --progress --color --optimize-minimize --optimize-dedupe --optimize-occurence-order", - "prepublish": "gulp clean && tsc", - "dev": "webpack-dev-server --hot --inline --colors --display-error-details --display-cached", - "start": "npm run dev", - "test": "gulp lint" + "flow.install:typings": "./node_modules/.bin/typings install", + "flow.compile": "npm run flow.install:typings && npm run flow.compile:common && npm run flow.compile:system ", + "flow.compile:common": "./node_modules/.bin/tsc", + "flow.compile:system": "./.config/bundle-system.js", + "flow.copy:src": "./node_modules/.bin/cpy ng2-select.ts \"components/*.ts\" ts --parents", + "flow.clean": "./node_modules/.bin/del bundles coverage demo-build typings \"components/**/*.+(js|d.ts|js.map)\" dist \"ng2-select.+(js|d.ts|js.map)\"", + "flow.deploy:gh-pages": "npm run flow.build:prod && ./node_modules/.bin/gh-pages -d demo-build", + "flow.eslint": "./node_modules/.bin/eslint --ignore-path .gitignore --ext js --fix . .config", + "flow.tslint": "./node_modules/.bin/gulp lint", + "flow.lint": "npm run flow.eslint && npm run flow.tslint", + "flow.changelog": "./node_modules/.bin/conventional-changelog -i CHANGELOG.md -s -p angular -v", + "flow.github-release": "conventional-github-releaser -p angular", + "flow.build:prod": "NODE_ENV=production ./node_modules/.bin/webpack --progress --color", + "flow.build:dev": "./node_modules/.bin/webpack --progress --color", + "flow.serve:dev": "./node_modules/.bin/webpack-dev-server --hot --inline --colors --display-error-details --display-cached", + "flow.serve:prod": "NODE_ENV=production ./node_modules/.bin/webpack-dev-server --hot --inline --colors --display-error-details --display-cached", + "prepublish": "npm run flow.clean && npm run flow.compile", + "postpublish": "npm run flow.deploy:gh-pages", + "start": "npm run flow.serve:dev", + "pretest": "npm run flow.lint", + "preversion": "npm test", + "version": "npm run flow.changelog && git add -A", + "postversion": "git push origin development && git push --tags" }, "main": "ng2-select.js", "typings": "ng2-select.d.ts", @@ -27,40 +45,52 @@ "url": "https://github.com/valor-software/ng2-select/issues" }, "homepage": "https://github.com/valor-software/ng2-select#readme", + "peerDependencies": { + "angular2": "2.0.0-beta.15" + }, "dependencies": {}, "devDependencies": { - "angular2": "2.0.0-beta.1", + "angular2": "2.0.0-beta.15", "bootstrap": "3.3.6", "clean-webpack-plugin": "0.1.8", "compression-webpack-plugin": "0.3.1", - "es6-shim": "0.33.13", - "eslint": "1.10.3", + "conventional-changelog-cli": "1.1.1", + "conventional-github-releaser": "1.1.2", + "copy-webpack-plugin": "2.1.1", + "cpy-cli": "1.0.0", + "del-cli": "0.2.0", + "es6-promise": "3.1.2", + "es6-shim": "0.35.0", + "es7-reflect-metadata": "1.6.0", + "eslint-config-valorsoft": "0.0.10", "exports-loader": "0.6.3", "file-loader": "0.8.5", + "gh-pages": "0.11.0", "gulp": "3.9.1", - "gulp-clean": "0.3.2", - "gulp-eslint": "1.1.1", "gulp-size": "2.1.0", - "gulp-tsc": "1.1.4", - "gulp-tslint": "4.3.5", - "html-loader": "0.4.2", + "gulp-tslint": "github:valorkin/gulp-tslint", + "html-loader": "0.4.3", + "html-webpack-plugin": "2.16.0", "markdown-loader": "0.1.7", "marked": "0.3.5", - "moment": "2.12.0", - "ng2-bootstrap": "1.0.11", + "moment": "2.13.0", + "ng2-bootstrap": "1.0.13", "pre-commit": "1.1.2", "prismjs": "valorkin/prism", "prismjs-loader": "0.0.2", "raw-loader": "0.5.1", - "reflect-metadata": "0.1.2", + "reflect-metadata": "0.1.3", "require-dir": "0.3.0", - "rxjs": "5.0.0-beta.0", + "rxjs": "5.0.0-beta.2", + "systemjs-builder": "0.15.15", "ts-loader": "0.8.2", - "tslint": "3.7.1", - "typescript": "1.8.9", - "webpack": "1.12.15", - "webpack-dev-server": "1.14.0", - "zone.js": "0.6.10" + "tslint": "3.7.4", + "tslint-config-valorsoft": "0.0.4", + "typescript": "1.8.10", + "typings": "0.8.1", + "webpack": "1.13.0", + "webpack-dev-server": "1.14.1", + "zone.js": "0.6.12" }, "contributors": [ { diff --git a/tsconfig.json b/tsconfig.json index 0648cae7..6fb213a6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { - "version": "1.7.5", "compilerOptions": { "target": "es5", "module": "commonjs", - "sourceMap": true, + "moduleResolution": "node", + "sourceMap": false, "declaration": true, - "removeComments": true, + "removeComments": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "noImplicitAny": true, @@ -16,6 +16,7 @@ "node_modules" ], "files": [ + "./typings/browser.d.ts", "./ng2-select.ts" ] } diff --git a/tslint.json b/tslint.json index a4120611..119e1146 100644 --- a/tslint.json +++ b/tslint.json @@ -1,56 +1,4 @@ { - "rules": { - "class-name": true, - "comment-format": [true, "check-space"], - "curly": true, - "eofline": true, - "forin": true, - "indent": [true, "spaces"], - "label-position": true, - "label-undefined": true, - "max-line-length": [false, 140], - "no-arg": true, - "no-bitwise": true, - "no-console": [true, - "debug", - "info", - "time", - "timeEnd", - "trace" - ], - "no-construct": true, - "no-debugger": true, - "no-duplicate-key": true, - "no-duplicate-variable": true, - "no-empty": false, - "no-eval": true, - "no-shadowed-variable": true, - "no-string-literal": true, - "no-switch-case-fall-through": true, - "no-trailing-comma": true, - "no-trailing-whitespace": true, - "no-unused-expression": true, - "no-unused-variable": false, - "no-unreachable": true, - "no-use-before-declare": true, - "no-var-keyword": true, - "one-line": [true, - "check-open-brace", - "check-catch", - "check-else", - "check-whitespace" - ], - "quotemark": [true, "single"], - "radix": true, - "semicolon": true, - "sort-object-literal-keys": false, - "triple-equals": [true, "allow-null-check"], - "variable-name": false, - "whitespace": [true, - "check-branch", - "check-decl", - "check-operator", - "check-separator" - ] - } + "extends": "./node_modules/tslint-config-valorsoft/tslint.json", + "rulesDirectory": "./node_modules/codelyzer/dist/src" } diff --git a/typings.json b/typings.json new file mode 100644 index 00000000..1e19f776 --- /dev/null +++ b/typings.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "webpack": "registry:npm/webpack#1.12.9+20160219013405" + }, + "devDependencies": {}, + "ambientDependencies": { + "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654", + "jasmine": "registry:dt/jasmine#2.2.0+20160317120654", + "require": "registry:dt/require#2.1.20+20160316155526" + } +} diff --git a/webpack.config.js b/webpack.config.js index f98d580a..54fb64d7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,35 +1,35 @@ -var path = require('path'); -var marked = require('marked'); -var webpack = require('webpack'); +/* eslint global-require: 0 */ +'use strict'; -var Clean = require('clean-webpack-plugin'); -var CompressionPlugin = require('compression-webpack-plugin'); +const path = require('path'); +const marked = require('marked'); +const webpack = require('webpack'); +const reqPrism = require('prismjs'); +const CompressionPlugin = require('compression-webpack-plugin'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); // marked renderer hack -marked.Renderer.prototype.code = function (code, lang) { - var out = this.options.highlight(code, lang); +marked.Renderer.prototype.code = function renderCode(code, lang) { + const out = this.options.highlight(code, lang); + const classMap = this.options.langPrefix + lang; if (!lang) { - return '
' + out + '\n
'; + return `
${out}\n
`; } - - var classMap = this.options.langPrefix + lang; - return '
' + out + '\n
\n'; + return `
${out}\n
\n`; }; /*eslint no-process-env:0, camelcase:0*/ -var isProduction = (process.env.NODE_ENV || 'development') === 'production'; - -var src = 'demo'; -//var absSrc = path.join(__dirname, src); -var dest = '/build'; -var absDest = path.join(__dirname, dest); +const isProduction = (process.env.NODE_ENV || 'development') === 'production'; +const devtool = process.env.NODE_ENV === 'test' ? 'inline-source-map' : 'source-map'; +const dest = 'demo-build'; +const absDest = root(dest); -var config = { +const config = { // isProduction ? 'source-map' : 'evale', - devtool: 'source-map', - debug: true, - cache: true, + devtool, + debug: false, verbose: true, displayErrorDetails: true, @@ -40,18 +40,20 @@ var config = { }, resolve: { + cache: false, root: __dirname, - extensions: ['', '.ts', '.js', '.json'], - alias: {} + extensions: ['', '.ts', '.js', '.json'] }, entry: { angular2: [ // Angular 2 Deps - 'zone.js/dist/zone-microtask', + 'es6-shim', + 'es6-promise', + 'zone.js', 'reflect-metadata', - 'angular2/core', - 'angular2/common' + 'angular2/common', + 'angular2/core' ], 'angular2-select': ['ng2-select'], 'angular2-select-demo': 'demo' @@ -69,20 +71,20 @@ var config = { inline: true, colors: true, historyApiFallback: true, - contentBase: src, - publicPath: dest + contentBase: dest, + //publicPath: dest, + outputPath: dest, + watchOptions: {aggregateTimeout: 300, poll: 1000} }, markdownLoader: { langPrefix: 'language-', - highlight: function (code, lang) { - var language = !lang || lang === 'html' ? 'markup' : lang; - if (!global.Prism) { - global.Prism = require('prismjs'); - } - var Prism = global.Prism; + highlight(code, lang) { + const language = !lang || lang === 'html' ? 'markup' : lang; + const Prism = global.Prism || reqPrism; + if (!Prism.languages[language]) { - require('prismjs/components/prism-' + language + '.js'); + require(`prismjs/components/prism-${language}.js`); } return Prism.highlight(code, Prism.languages[language]); } @@ -91,64 +93,65 @@ var config = { loaders: [ // support markdown {test: /\.md$/, loader: 'html?minimize=false!markdown'}, - // Support for *.json files. {test: /\.json$/, loader: 'json'}, - // Support for CSS as raw text {test: /\.css$/, loader: 'raw'}, - // support for .html as raw text {test: /\.html$/, loader: 'raw'}, - // Support for .ts files. { test: /\.ts$/, loader: 'ts', - exclude: [ - /\.min\.js$/, - /\.spec\.ts$/, - /\.e2e\.ts$/, - /web_modules/, - /test/ - ] + query: { + compilerOptions: { + removeComments: true, + noEmitHelpers: false + } + }, + exclude: [/\.(spec|e2e)\.ts$/] } ], noParse: [ /rtts_assert\/src\/rtts_assert/, - /reflect-metadata/ + /reflect-metadata/, + /zone\.js\/dist\/zone-microtask/ ] }, plugins: [ - new Clean(['build']), + //new Clean([dest]), + new webpack.optimize.DedupePlugin(), + new webpack.optimize.OccurenceOrderPlugin(true), new webpack.optimize.CommonsChunkPlugin({ name: 'angular2', minChunks: Infinity, filename: 'angular2.js' }), - new webpack.optimize.DedupePlugin({ - __isProduction: isProduction - }), - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.DedupePlugin() + // static assets + new CopyWebpackPlugin([{from: 'demo/favicon.ico', to: 'favicon.ico'}]), + new CopyWebpackPlugin([{from: 'demo/assets', to: 'assets'}]), + // generating html + new HtmlWebpackPlugin({template: 'demo/index.html'}) ], - pushPlugins: function () { + pushPlugins() { if (!isProduction) { return; } - - this.plugins.push.apply(this.plugins, [ + const plugins = [ //production only new webpack.optimize.UglifyJsPlugin({ + beautify: false, + mangle: false, + comments: false, compress: { - warnings: false, - drop_debugger: false - }, - output: { - comments: false - }, - beautify: false + screw_ie8: true + //warnings: false, + //drop_debugger: false + } + //verbose: true, + //beautify: false, + //quote_style: 3 }), new CompressionPlugin({ asset: '{file}.gz', @@ -157,10 +160,19 @@ var config = { threshold: 10240, minRatio: 0.8 }) - ]); + ]; + + this + .plugins + .push + .apply(plugins); } }; config.pushPlugins(); module.exports = config; + +function root(partialPath) { + return path.join(__dirname, partialPath); +}