Skip to content

Commit

Permalink
fix(angular): ssr distFolder path should be more correctly defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed May 4, 2023
1 parent 01769bc commit b56e601
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {<%= rootModuleClassName %>} from './src/<%= main.slice(0, -3) %>';
// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/apps/<%= project %>/browser');
const distFolder = join(process.cwd(), '<%= browserBundleOutputPath %>');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';

// Our Universal express-engine (found @ https:/angular/universal/tree/main/modules/express-engine)
Expand Down Expand Up @@ -57,4 +57,4 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}

export * from './src/<%= main.slice(0, -3) %>';
export * from './src/<%= main.slice(0, -3) %>';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import bootstrap from './src/<%= main.slice(0, -3) %>';
// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/apps/<%= project %>/browser');
const distFolder = join(process.cwd(), '<%= browserBundleOutputPath %>');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';

// Our Universal express-engine (found @ https:/angular/universal/tree/main/modules/express-engine)
Expand Down
17 changes: 12 additions & 5 deletions packages/angular/src/generators/setup-ssr/lib/generate-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { Schema } from '../schema';

export function generateSSRFiles(tree: Tree, schema: Schema) {
const projectRoot = readProjectConfiguration(tree, schema.project).root;
const projectConfig = readProjectConfiguration(tree, schema.project);
const projectRoot = projectConfig.root;
const browserBundleOutputPath =
projectConfig.targets.build.options.outputPath;

const pathToFiles = joinPathFragments(__dirname, '..', 'files');

Expand All @@ -23,14 +26,16 @@ export function generateSSRFiles(tree: Tree, schema: Schema) {
tree,
joinPathFragments(pathToFiles, 'standalone'),
projectRoot,
{ ...schema, tpl: '' }

{ ...schema, browserBundleOutputPath, tpl: '' }
);
} else {
generateFiles(
tree,
joinPathFragments(pathToFiles, 'ngmodule', 'base'),
projectRoot,
{ ...schema, tpl: '' }

{ ...schema, browserBundleOutputPath, tpl: '' }
);

const { major: angularMajorVersion, version: angularVersion } =
Expand All @@ -41,15 +46,17 @@ export function generateSSRFiles(tree: Tree, schema: Schema) {
tree,
joinPathFragments(pathToFiles, 'ngmodule', 'v14'),
projectRoot,
{ ...schema, tpl: '' }

{ ...schema, browserBundleOutputPath, tpl: '' }
);
}
if (lt(angularVersion, '15.2.0')) {
generateFiles(
tree,
joinPathFragments(pathToFiles, 'ngmodule', 'pre-v15-2'),
projectRoot,
{ ...schema, tpl: '' }

{ ...schema, browserBundleOutputPath, tpl: '' }
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import type { Schema } from '../schema';
export function updateProjectConfig(tree: Tree, schema: Schema) {
let projectConfig = readProjectConfiguration(tree, schema.project);
const buildTarget = projectConfig.targets.build;

buildTarget.options.outputPath = `dist/apps/${schema.project}/browser`;
const baseOutputPath = `${buildTarget.options.outputPath}`;
buildTarget.options.outputPath = joinPathFragments(baseOutputPath, 'browser');

const buildConfigurations = projectConfig.targets.build.configurations;
const configurations: Record<string, {}> = {};
Expand All @@ -30,7 +30,7 @@ export function updateProjectConfig(tree: Tree, schema: Schema) {
dependsOn: ['build'],
executor: '@angular-devkit/build-angular:server',
options: {
outputPath: `dist/${projectConfig.root}/server`,
outputPath: joinPathFragments(baseOutputPath, 'server'),
main: joinPathFragments(projectConfig.root, schema.serverFileName),
tsConfig: joinPathFragments(projectConfig.root, 'tsconfig.server.json'),
...(buildTarget.options ? getServerOptions(buildTarget.options) : {}),
Expand Down
3 changes: 1 addition & 2 deletions packages/angular/src/generators/setup-ssr/setup-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ export async function setupSsr(tree: Tree, schema: Schema) {
validateOptions(tree, schema);
const options = normalizeOptions(tree, schema);

updateProjectConfig(tree, options);
generateSSRFiles(tree, options);

if (!options.standalone) {
updateAppModule(tree, options);
}

updateProjectConfig(tree, options);

const pkgVersions = versions(tree);

addDependenciesToPackageJson(
Expand Down

0 comments on commit b56e601

Please sign in to comment.