diff --git a/package.json b/package.json index 342ad8a5ac7a..2fdf07ad3e0a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "@angular/compiler-cli": "^2.3.1", "@angular/core": "^2.3.1", "@angular/tsc-wrapped": "^0.5.0", - "async": "^2.1.4", "autoprefixer": "^6.5.3", "chalk": "^1.1.3", "common-tags": "^1.3.1", @@ -103,7 +102,6 @@ "webpack": "~2.2.0", "webpack-dev-server": "~2.2.0", "webpack-merge": "^2.4.0", - "webpack-sources": "^0.1.3", "zone.js": "^0.7.2" }, "ember-addon": { diff --git a/packages/@angular/cli/lib/webpack/compression-plugin.ts b/packages/@angular/cli/lib/webpack/compression-plugin.ts deleted file mode 100644 index 6bae1ea0f697..000000000000 --- a/packages/@angular/cli/lib/webpack/compression-plugin.ts +++ /dev/null @@ -1,112 +0,0 @@ -/** Forked from https://github.com/webpack/compression-webpack-plugin. */ -const async = require('async'); -const url = require('url'); - -const RawSource = require('webpack-sources/lib/RawSource'); - - -export interface CompressionPluginOptions { - algorithm?: string; - asset?: string; - level?: number; - flush?: boolean; - chunkSize?: number; - test?: RegExp | RegExp[]; - windowBits?: number; - memLevel?: number; - strategy?: number; - dictionary?: any; - threshold?: number; - minRatio?: number; -} - - -export class CompressionPlugin { - private asset = '[path].gz[query]'; - private algorithm: Function; - private compressionOptions: any = {}; - private test: RegExp[]; - private threshold = 0; - private minRatio = 0.8; - - constructor(options: CompressionPluginOptions = {}) { - if (options.hasOwnProperty('asset')) { - this.asset = options.asset; - } - - const algorithm = options.hasOwnProperty('algorithm') ? options.algorithm : 'gzip'; - - const zlib = require('zlib'); - - this.compressionOptions = {}; - this.algorithm = zlib[algorithm]; - if (!this.algorithm) { - throw new Error(`Algorithm not found in zlib: "${algorithm}".`); - } - - this.compressionOptions = { - level: options.level || 9, - flush: options.flush, - chunkSize: options.chunkSize, - windowBits: options.windowBits, - memLevel: options.memLevel, - strategy: options.strategy, - dictionary: options.dictionary - }; - - if (options.hasOwnProperty('test')) { - if (Array.isArray(options.test)) { - this.test = options.test as RegExp[]; - } else { - this.test = [options.test as RegExp]; - } - } - if (options.hasOwnProperty('threshold')) { - this.threshold = options.threshold; - } - if (options.hasOwnProperty('minRatio')) { - this.minRatio = options.minRatio; - } - } - - apply(compiler: any) { - compiler.plugin('this-compilation', (compilation: any) => { - compilation.plugin('optimize-assets', (assets: any, callback: Function) => { - async.forEach(Object.keys(assets), (file: string, callback: Function) => { - if (this.test.every((t) => !t.test(file))) { - return callback(); - } - - const asset = assets[file]; - let content = asset.source(); - if (!Buffer.isBuffer(content)) { - content = new Buffer(content, 'utf-8'); - } - - const originalSize = content.length; - if (originalSize < this.threshold) { - return callback(); - } - - this.algorithm(content, this.compressionOptions, (err: Error, result: string) => { - if (err) { - return callback(err); - } - if (result.length / originalSize > this.minRatio) { - return callback(); - } - - const parse = url.parse(file); - const newFile = this.asset - .replace(/\[file]/g, file) - .replace(/\[path]/g, parse.pathname) - .replace(/\[query]/g, parse.query || ''); - - assets[newFile] = new RawSource(result); - callback(); - }); - }, callback); - }); - }); - } -} diff --git a/packages/@angular/cli/models/webpack-configs/production.ts b/packages/@angular/cli/models/webpack-configs/production.ts index 055f0bdc345d..5db04d93216c 100644 --- a/packages/@angular/cli/models/webpack-configs/production.ts +++ b/packages/@angular/cli/models/webpack-configs/production.ts @@ -4,7 +4,6 @@ import * as fs from 'fs'; import { stripIndent } from 'common-tags'; import { StaticAssetPlugin } from '../../plugins/static-asset'; import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin'; -import { CompressionPlugin } from '../../lib/webpack/compression-plugin'; import { WebpackConfigOptions } from '../webpack-config'; @@ -75,12 +74,6 @@ export const getProdConfig = function (wco: WebpackConfigOptions) { mangle: { screw_ie8: true }, compress: { screw_ie8: true, warnings: buildOptions.verbose }, sourceMap: buildOptions.sourcemap - }), - new CompressionPlugin({ - asset: '[path].gz[query]', - algorithm: 'gzip', - test: /\.js$|\.html$|\.css$/, - threshold: 10240 }) ].concat(extraPlugins) }; diff --git a/packages/@angular/cli/package.json b/packages/@angular/cli/package.json index 72bb50093118..de8dc10c07d8 100644 --- a/packages/@angular/cli/package.json +++ b/packages/@angular/cli/package.json @@ -28,7 +28,6 @@ "dependencies": { "@ngtools/json-schema": "1.0.3", "@ngtools/webpack": "1.2.9", - "async": "^2.1.4", "autoprefixer": "^6.5.3", "chalk": "^1.1.3", "common-tags": "^1.3.1", @@ -84,7 +83,6 @@ "webpack": "~2.2.0", "webpack-dev-server": "~2.2.0", "webpack-merge": "^2.4.0", - "webpack-sources": "^0.1.3", "zone.js": "^0.7.2" }, "ember-addon": {