Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): never split polyfills in test
Browse files Browse the repository at this point in the history
Fix #10485
  • Loading branch information
filipesilva authored and hansl committed Jun 6, 2018
1 parent 4df1039 commit fd06d95
Showing 1 changed file with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
* 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 * as path from 'path';
import * as glob from 'glob';

// import { CliConfig } from '../config';
import * as path from 'path';
import * as webpack from 'webpack';
import { WebpackConfigOptions, WebpackTestOptions } from '../build-options';


Expand All @@ -23,19 +20,20 @@ import { WebpackConfigOptions, WebpackTestOptions } from '../build-options';
*
*/


export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
export function getTestConfig(
wco: WebpackConfigOptions<WebpackTestOptions>,
): webpack.Configuration {
const { root, buildOptions } = wco;

const extraRules: any[] = [];
const extraPlugins: any[] = [];
const extraRules: webpack.Rule[] = [];
const extraPlugins: webpack.Plugin[] = [];

// if (buildOptions.codeCoverage && CliConfig.fromProject()) {
if (buildOptions.codeCoverage) {
const codeCoverageExclude = buildOptions.codeCoverageExclude;
let exclude: (string | RegExp)[] = [
const exclude: (string | RegExp)[] = [
/\.(e2e|spec)\.ts$/,
/node_modules/
/node_modules/,
];

if (codeCoverageExclude) {
Expand All @@ -51,7 +49,7 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
options: { esModules: true },
enforce: 'post',
exclude
exclude,
});
}

Expand All @@ -60,34 +58,31 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
resolve: {
mainFields: [
...(wco.supportES2015 ? ['es2015'] : []),
'browser', 'module', 'main'
]
'browser', 'module', 'main',
],
},
devtool: buildOptions.sourceMap ? 'inline-source-map' : 'eval',
entry: {
main: path.resolve(root, buildOptions.main)
main: path.resolve(root, buildOptions.main),
},
module: {
rules: [].concat(extraRules as any)
rules: extraRules,
},
plugins: extraPlugins,
optimization: {
// runtimeChunk: 'single',
splitChunks: {
chunks: buildOptions.commonChunk ? 'all' : 'initial',
chunks: ((chunk: { name: string }) => chunk.name !== 'polyfills'),
cacheGroups: {
vendors: false,
vendor: {
name: 'vendor',
chunks: 'initial',
test: (module: any, chunks: Array<{ name: string }>) => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName)
&& !chunks.some(({ name }) => name === 'polyfills');
},
test: /[\\/]node_modules[\\/]/,
},
}
}
},
},
},
};
// Webpack typings don't yet include the function form for 'chunks',
// or the built-in vendors cache group.
} as {} as webpack.Configuration;
}

0 comments on commit fd06d95

Please sign in to comment.