Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// tslint:disable
// TODO: cleanup this file, it's copied as is from Angular CLI.

import { basename, normalize } from '@angular-devkit/core';
import * as path from 'path';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
Expand All @@ -11,6 +10,7 @@ import { BaseHrefWebpackPlugin } from '../../lib/base-href-webpack';
import { IndexHtmlWebpackPlugin } from '../../plugins/index-html-webpack-plugin';
import { ExtraEntryPoint } from '../../../browser';
import { WebpackConfigOptions } from '../build-options';
import { computeBundleName } from './utils';

/**
+ * license-webpack-plugin has a peer dependency on webpack-sources, list it in a comment to
Expand All @@ -28,15 +28,8 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
// Figure out which are the lazy loaded bundle names.
const lazyChunkBundleNames = ([...buildOptions.styles, ...buildOptions.scripts] as ExtraEntryPoint[])
.filter(entry => entry.lazy)
.map(entry => {
if (!entry.bundleName) {
return basename(
normalize(entry.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')),
);
} else {
return entry.bundleName;
}
});
// We don't really need a default name because we pre-filtered by lazy only entries.
.map(style => computeBundleName(style, 'not-lazy'));

const generateIndexHtml = false;
if (generateIndexHtml) {
Expand Down Expand Up @@ -85,17 +78,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
}

const globalStylesBundleNames = (buildOptions.styles as ExtraEntryPoint[])
.map(style => {
if (style.bundleName) {
return style.bundleName;
} else if (style.lazy) {
return basename(
normalize(style.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')),
);
} else {
return 'styles';
}
});
.map(style => computeBundleName(style, 'styles'));

return {
devtool: sourcemaps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// tslint:disable
// TODO: cleanup this file, it's copied as is from Angular CLI.

import { basename, normalize } from '@angular-devkit/core';
import * as path from 'path';
import { HashedModuleIdsPlugin } from 'webpack';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
Expand All @@ -14,6 +13,7 @@ import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin';
import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin';
import { findUp } from '../../utilities/find-up';
import { AssetPattern, ExtraEntryPoint } from '../../../browser';
import { computeBundleName } from './utils';

const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
Expand Down Expand Up @@ -60,18 +60,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
if (buildOptions.scripts.length > 0) {
const globalScriptsByBundleName = (buildOptions.scripts as ExtraEntryPoint[])
.reduce((prev: { bundleName: string, paths: string[], lazy: boolean }[], curr) => {
let bundleName = curr.bundleName;
if (!bundleName) {
if (curr.lazy) {
bundleName = basename(
normalize(curr.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')),
);
}
else {
bundleName = 'scripts';
}
}

const bundleName = computeBundleName(curr, 'scripts');
const resolvedPath = path.resolve(root, curr.input);
let existingEntry = prev.find((el) => el.bundleName === bundleName);
if (existingEntry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// tslint:disable
// TODO: cleanup this file, it's copied as is from Angular CLI.

import { basename, normalize } from '@angular-devkit/core';
import * as webpack from 'webpack';
import * as path from 'path';
import { SuppressExtractedTextChunksWebpackPlugin } from '../../plugins/webpack';
Expand All @@ -10,6 +9,7 @@ import { WebpackConfigOptions } from '../build-options';
import { findUp } from '../../utilities/find-up';
import { RawCssLoader } from '../../plugins/webpack';
import { ExtraEntryPoint } from '../../../browser';
import { computeBundleName } from './utils';

const postcssUrl = require('postcss-url');
const autoprefixer = require('autoprefixer');
Expand Down Expand Up @@ -169,18 +169,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
// Process global styles.
if (buildOptions.styles.length > 0) {
(buildOptions.styles as ExtraEntryPoint[]).forEach(style => {
let bundleName = style.bundleName;
if (!bundleName) {
if (style.lazy) {
bundleName = basename(
normalize(style.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')),
);
}
else {
bundleName = 'styles';
}
}

const bundleName = computeBundleName(style, 'styles');;
const resolvedPath = path.resolve(root, style.input);

// Add style entry points.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// TODO: cleanup this file, it's copied as is from Angular CLI.

import * as path from 'path';
import { basename, normalize } from '@angular-devkit/core';
import { ExtraEntryPoint } from '../../../browser';

export const ngAppResolve = (resolvePath: string): string => {
return path.resolve(process.cwd(), resolvePath);
Expand Down Expand Up @@ -58,3 +60,15 @@ export function getOutputHashFormat(option: string, length = 20): HashFormat {
/* tslint:enable:max-line-length */
return hashFormats[option] || hashFormats['none'];
}

export function computeBundleName(entry: ExtraEntryPoint, defaultName: string){
if (entry.bundleName) {
return entry.bundleName;
} else if (entry.lazy) {
return basename(
normalize(entry.input.replace(/\.(js|css|scss|sass|less|styl)$/i, '')),
);
} else {
return defaultName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
// Add webpack config.
const webpackConfig = config.buildWebpack.webpackConfig;
const webpackMiddlewareConfig = {
// logLevel: 'error', // Hide webpack output because its noisy.
logLevel: 'error', // Hide webpack output because its noisy.
watchOptions: { poll: options.poll },
publicPath: '/_karma_webpack_/',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TODO: cleanup this file, it's copied as is from Angular CLI.

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

export function generateEntryPoints(appConfig: any) {
let entryPoints = ['polyfills', 'sw-register'];
Expand All @@ -10,10 +11,10 @@ export function generateEntryPoints(appConfig: any) {
[
...(appConfig.styles as ExtraEntryPoint[])
.filter(entry => !entry.lazy)
.map(entry => entry.bundleName || 'styles'),
.map(entry => computeBundleName(entry, 'styles')),
...(appConfig.scripts as ExtraEntryPoint[])
.filter(entry => !entry.lazy)
.map(entry => entry.bundleName || 'scripts'),
.map(entry => computeBundleName(entry, 'scripts')),
].forEach(bundleName => {
if (entryPoints.indexOf(bundleName) === -1) {
entryPoints.push(bundleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export interface AssetPattern {

export interface ExtraEntryPoint {
input: string;
bundleName: string;
bundleName?: string;
lazy: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
`${projectRoot}tsconfig.app.json`,
`${projectRoot}tsconfig.spec.json`,
`${rootFilesRoot}tsconfig.app.json`,
`${rootFilesRoot}tsconfig.spec.json`,
],
exclude: [
'**/node_modules/**',
Expand Down
62 changes: 51 additions & 11 deletions packages/schematics/angular/migrations/update-6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,31 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
defaultAppNamePrefix = config.project.name;
}

const buildDefaults: JsonObject = config.defaults && config.defaults.build
? {
sourceMap: config.defaults.build.sourcemaps,
progress: config.defaults.build.progress,
poll: config.defaults.build.poll,
deleteOutputPath: config.defaults.build.deleteOutputPath,
preserveSymlinks: config.defaults.build.preserveSymlinks,
showCircularDependencies: config.defaults.build.showCircularDependencies,
commonChunk: config.defaults.build.commonChunk,
namedChunks: config.defaults.build.namedChunks,
} as JsonObject
: {};

const serveDefaults: JsonObject = config.defaults && config.defaults.serve
? {
port: config.defaults.serve.port,
host: config.defaults.serve.host,
ssl: config.defaults.serve.ssl,
sslKey: config.defaults.serve.sslKey,
sslCert: config.defaults.serve.sslCert,
proxyConfig: config.defaults.serve.proxyConfig,
} as JsonObject
: {};


const apps = config.apps || [];
// convert the apps to projects
const projectMap = apps
Expand All @@ -179,22 +204,25 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {

function _mapAssets(asset: string | JsonObject) {
if (typeof asset === 'string') {
return { glob: asset, input: normalize('/' + appRoot + '/'), output: '/' };
if (tree.exists(app.root + '/' + asset)) {
// If it exists in the tree, then it is a file.
return { glob: asset, input: normalize(appRoot + '/'), output: '/' };
} else {
// If it does not exist, it is either a folder or something we can't statically know.
// Folders must get a recursive star glob.
return { glob: '**/*', input: normalize(appRoot + '/' + asset), output: '/' + asset };
}
} else {
if (asset.output) {
return {
glob: asset.glob,
input: normalize('/' + appRoot + '/' + asset.input),
output: normalize('/'
+ ((asset.output as string).startsWith(outDir)
? (asset.output as string).slice(outDir.length)
: (asset.output as string)),
),
input: normalize(appRoot + '/' + asset.input),
output: normalize('/' + asset.output as string),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not need the logic removed above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in retrospective that logic never made much sense. Paths were already relative to the output dir. So output dist/folder would have actually gone to dist/dist/folder. The absolute paths for the source just messed resolution up as well.

};
} else {
return {
glob: asset.glob,
input: normalize('/' + appRoot + '/' + asset.input),
input: normalize(appRoot + '/' + asset.input),
output: '/',
};
}
Expand All @@ -210,6 +238,10 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
}

return Object.keys(environments).reduce((acc, environment) => {
if (source === environments[environment]) {
return acc;
}

let isProduction = false;

const environmentContent = tree.read(app.root + '/' + environments[environment]);
Expand All @@ -219,13 +251,16 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
.match(/production['"]?\s*[:=]\s*true/);
}

let configurationName;
// We used to use `prod` by default as the key, instead we now use the full word.
// Try not to override the production key if it's there.
if (environment == 'prod' && !environments['production'] && isProduction) {
environment = 'production';
configurationName = 'production';
} else {
configurationName = environment;
}

acc[environment] = {
acc[configurationName] = {
...(isProduction
? {
optimization: true,
Expand All @@ -241,7 +276,10 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
: {}
),
fileReplacements: [
{ from: `${app.root}/${source}`, to: `${outDir}/${environments[environment]}` },
{
src: `${app.root}/${source}`,
replaceWith: `${app.root}/${environments[environment]}`,
},
],
};

Expand Down Expand Up @@ -306,6 +344,7 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
main: appRoot + '/' + app.main || defaults.main,
polyfills: appRoot + '/' + app.polyfills || defaults.polyfills,
tsConfig: appRoot + '/' + app.tsconfig || defaults.tsConfig,
...buildDefaults,
};

buildOptions.assets = (app.assets || []).map(_mapAssets);
Expand All @@ -320,6 +359,7 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
// Serve target
const serveOptions: JsonObject = {
browserTarget: `${name}:build`,
...serveDefaults,
};
architect.serve = {
builder: `${builderPackage}:dev-server`,
Expand Down
Loading