Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): remove unused html webpack p…
Browse files Browse the repository at this point in the history
…lugins
  • Loading branch information
clydin authored and Keen Yee Liau committed Oct 4, 2018
1 parent 64d1524 commit 3bf2bb0
Show file tree
Hide file tree
Showing 8 changed files with 1,294 additions and 465 deletions.
1 change: 0 additions & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"copy-webpack-plugin": "4.5.2",
"file-loader": "2.0.0",
"glob": "7.1.3",
"html-webpack-plugin": "3.2.0",
"istanbul": "0.4.5",
"istanbul-instrumenter-loader": "3.0.1",
"karma-source-map-support": "1.3.0",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
// TODO: cleanup this file, it's copied as is from Angular CLI.

import * as path from 'path';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import { generateEntryPoints, packageChunkSort } from '../../utilities/package-chunk-sort';
import { BaseHrefWebpackPlugin } from '../../lib/base-href-webpack';
import { generateEntryPoints } from '../../utilities/package-chunk-sort';
import { IndexHtmlWebpackPlugin } from '../../plugins/index-html-webpack-plugin';
import { WebpackConfigOptions } from '../build-options';
import { normalizeExtraEntryPoints } from './utils';
Expand All @@ -26,37 +24,9 @@ import { normalizeExtraEntryPoints } from './utils';
+ */

export function getBrowserConfig(wco: WebpackConfigOptions) {
const { root, projectRoot, buildOptions } = wco;


const { root, buildOptions } = wco;
let extraPlugins: any[] = [];

// Figure out which are the lazy loaded bundle names.
const lazyChunkBundleNames = normalizeExtraEntryPoints(
// We don't really need a default name because we pre-filtered by lazy only entries.
[...buildOptions.styles, ...buildOptions.scripts], 'not-lazy')
.filter(entry => entry.lazy)
.map(entry => entry.bundleName)

const generateIndexHtml = false;
if (generateIndexHtml) {
extraPlugins.push(new HtmlWebpackPlugin({
template: path.resolve(root, buildOptions.index),
filename: path.resolve(buildOptions.outputPath, buildOptions.index),
chunksSortMode: packageChunkSort(buildOptions),
excludeChunks: lazyChunkBundleNames,
xhtml: true,
minify: buildOptions.optimization ? {
caseSensitive: true,
collapseWhitespace: true,
keepClosingSlash: true
} : false
}));
extraPlugins.push(new BaseHrefWebpackPlugin({
baseHref: buildOptions.baseHref as string
}));
}

let sourcemaps: string | false = false;
if (buildOptions.sourceMap) {
// See https://webpack.js.org/configuration/devtool/ for sourcemap types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

// Exports the webpack plugins we use internally.
export { BaseHrefWebpackPlugin } from '../lib/base-href-webpack/base-href-webpack-plugin';
export { CleanCssWebpackPlugin, CleanCssWebpackPluginOptions } from './cleancss-webpack-plugin';
export { BundleBudgetPlugin, BundleBudgetPluginOptions } from './bundle-budget';
export { ScriptsWebpackPlugin, ScriptsWebpackPluginOptions } from './scripts-webpack-plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// tslint:disable
// TODO: cleanup this file, it's copied as is from Angular CLI.

import { ExtraEntryPoint } from '../../browser/schema';
import { normalizeExtraEntryPoints } from '../models/webpack-configs/utils';

export function generateEntryPoints(appConfig: any) {
let entryPoints = ['polyfills', 'sw-register'];
export function generateEntryPoints(
appConfig: { styles: ExtraEntryPoint[], scripts: ExtraEntryPoint[] },
) {
const entryPoints = ['polyfills', 'sw-register'];

// Add all styles/scripts, except lazy-loaded ones.
[
...normalizeExtraEntryPoints(appConfig.styles as ExtraEntryPoint[], 'styles')
...normalizeExtraEntryPoints(appConfig.styles, 'styles')
.filter(entry => !entry.lazy)
.map(entry => entry.bundleName),
...normalizeExtraEntryPoints(appConfig.scripts as ExtraEntryPoint[], 'scripts')
...normalizeExtraEntryPoints(appConfig.scripts, 'scripts')
.filter(entry => !entry.lazy)
.map(entry => entry.bundleName),
].forEach(bundleName => {
Expand All @@ -32,27 +31,3 @@ export function generateEntryPoints(appConfig: any) {

return entryPoints;
}

// Sort chunks according to a predefined order:
// inline, polyfills, all styles, vendor, main
export function packageChunkSort(appConfig: any) {
const entryPoints = generateEntryPoints(appConfig);

function sort(left: any, right: any) {
let leftIndex = entryPoints.indexOf(left.names[0]);
let rightindex = entryPoints.indexOf(right.names[0]);

if (leftIndex > rightindex) {
return 1;
} else if (leftIndex < rightindex) {
return -1;
} else {
return 0;
}
}

// We need to list of entry points for the Ejected webpack config to work (we reuse the function
// defined above).
(sort as any).entryPoints = entryPoints;
return sort;
}
Loading

0 comments on commit 3bf2bb0

Please sign in to comment.