Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(universal): add support for Angular Universal #2318

Closed
wants to merge 1 commit into from

Conversation

devCrossNet
Copy link

add the possibility to scaffold a universal project with --universal

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@hansl
Copy link
Contributor

hansl commented Sep 23, 2016

Hi @devCrossNet, could you rebase this PR? It's obviously on top of previous commits, so there is some problem with it. Thanks!

@googlebot
Copy link

CLAs look good, thanks!

@devCrossNet
Copy link
Author

@hansl I rebased the branch

@@ -14,7 +14,7 @@ module.exports = {

beforeInstall: function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing your "space before ()" notation :)

@ritz078
Copy link
Contributor

ritz078 commented Sep 26, 2016

@devCrossNet guidelines to update an existing project to universal will be helpful.

@devCrossNet
Copy link
Author

@ritz078 @intellix added :-)

@devCrossNet
Copy link
Author

AoT is currently not working with universal.

@devCrossNet devCrossNet changed the title (feat): Universal Angular feature(universal): add support for Angular Universal Oct 1, 2016
@kuldeepkeshwar
Copy link

@devCrossNet what about lazy routing support ?

Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

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

Some first comments.

@@ -265,7 +266,21 @@ You can modify the these scripts in `package.json` to run whatever tool you pref

**The `--mobile` flag has been disabled temporarily. Sorry for the inconvenience.**

~~Angular-CLI includes support for offline applications via the `--` flag on `ng new`. Support is experimental, please see the angular/mobile-toolkit project and https://mobile.angular.io/ for documentation on how to make use of this functionality.~~
~~Angular-CLI includes support for offline applications via the `--` flag on `ng new`. Support is experimental,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that line necessary at all? If it is, the flag is empty.

Copy link
Author

Choose a reason for hiding this comment

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

I'll change this to --mobile

@@ -3,3 +3,7 @@
// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html

declare var System: any;
<% if(universal) { %>
/// <reference path="../node_modules/@types/node/index.d.ts" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead, include "types": [ "node" ] in the tsconfig. I don't want any relative /// references.

} else if (files.length > 1) {
throw new SilentError(`Multiple module files found: ${pathToCheck.replace(sourceRoot, '')}`);
if (files.length > 0) {
return files.map((file) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Single line, without the return. return files.map(file => path.join(pathToCheck, file));

"main": "main.ts",
"index": "index.html",<% if(!universal) { %>
"main": "main.ts",<% } %><% if(universal) { %>
"main": "client.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a new client file instead of keeping/overwriting main? Is there a reason you don't want main as the output of your app in universal? I understand the semantic differences, I'm just wondering if there's a technical reason.

Copy link
Author

Choose a reason for hiding this comment

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

I did not want to change so much in the CLI code. We can talk about a strategy to rename files. Because I need the main.ts file as client.ts in the universal context. This was the easiest solution for me to not implement "renaming files".

@devCrossNet devCrossNet force-pushed the universal-webpack branch 3 times, most recently from 7639230 to 611f337 Compare October 3, 2016 17:33
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
path.resolve(projectRoot, 'node_modules/rxjs'),
Copy link
Member

Choose a reason for hiding this comment

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

Exclude all node modules sourcemaps, its faster, more reliable, especially as more packages get added, like angularfire material etc. Users won't be able to turn these off, so we need to ignore them all.

Copy link
Author

Choose a reason for hiding this comment

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

I'll do that. Thanks.

module: {
rules: [
{
test: /\.js$/,
Copy link
Member

Choose a reason for hiding this comment

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

This used to be a preLoader, (or ideally?), if soo add enforce: 'pre'

Copy link
Author

Choose a reason for hiding this comment

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

yes, it was a preloader. but the preloader config attribute is not available anymore?! I got an error. I will use enforce: 'pre' thank you!


const fileName = path.resolve(outputDir, appConfig.index);
const data = fs.readFileSync(fileName, 'utf8').replace(
'<script src="http://localhost:35729/livereload.js?snipver=1"></script>',
Copy link
Member

Choose a reason for hiding this comment

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

what and why

Copy link
Author

Choose a reason for hiding this comment

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

I tried to replace it with webpack in the webpack-build-prod config. but I did not get it to work. I used the string-replacement plugin. I'll try it again. I just want to remove the live-reload-script in production.

console.log(stderr.toString());
});

this.webpackCompiler.plugin('compile', () => {});
Copy link
Member

Choose a reason for hiding this comment

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

this technically should hang and break compiling because compile requires a callback which is passed in, in addition to the compiler instance. Why is this and the rest of these events being done.

Copy link
Author

Choose a reason for hiding this comment

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

I just copied code from webpack-dev-server, removed unused code in the invalid-plugin and the left over was an empty function. I'll try to remove this. https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L30

private demon: any;
private liveServer: any;

constructor(private webpackCompiler: any, private webpackDevServerConfiguration: any) {
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose for not using webpack-dev-server. Additionally, if you are wanting to use an express server there is webpack-dev-middleware as well which has a lot of the api configuration to hook webpack into your existing express server.

Copy link
Member

Choose a reason for hiding this comment

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

If the concern is trying to hide the webpack-dev-middleware from the user, I'd rather see that being used in server.ts and then packaged/blackboxed universal module which runs the dev-middleware

Copy link
Author

Choose a reason for hiding this comment

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

I am not familiar with the webpack-dev-middleware. Is it possible to reload the whole server code when somethings change? Because in universal the server.ts file is part of the business logic and for DX it must reload the server code when the user changes something. I'll have a look at it. maybe we can chat or something?

@devCrossNet devCrossNet changed the base branch from master to universal October 4, 2016 18:41
@@ -20,6 +20,7 @@
"test:cli": "node tests/runner",
"test:inspect": "node --inspect --debug-brk tests/runner",
"test:packages": "node scripts/run-packages-spec.js",
"test:universal": "UNIVERSAL=true node tests/e2e_runner.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are not being ran in the CI atm, you might have to fiddle with travis.yml to see them run.

Copy link
Author

Choose a reason for hiding this comment

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

I know, but I was not sure if you want to have the universal tests in the master branch. But now as we have a universal branch, I'll enable the test.

@xzilja
Copy link

xzilja commented Oct 14, 2016

Hello, I believe myself and few other people have been following this feature for a while. Wanted to check in if there is any update on progress for universal support + if you guys need help with anything?

@devCrossNet
Copy link
Author

@iljadaderko I am on it. I hope I can get the requested changes (most of them) in this weekend. after that, I have to wait for another review.

@kuldeepkeshwar
Copy link

@devCrossNet any idea how will you be handling lazy routes (code split points) on server ?

add the possibility to scaffold a universal project with --universal
@devCrossNet
Copy link
Author

@kuldeepkeshwar I don't know. I have to talk about it with the team

@Brocco
Copy link
Contributor

Brocco commented Oct 14, 2016

Closing this PR to master, as this is being tracked/managed in a separate branch.

@Brocco Brocco closed this Oct 14, 2016
@hongbo-miao
Copy link

@Brocco can you put the new link here so we can track? thanks

@CanKattwinkel
Copy link

CanKattwinkel commented Oct 14, 2016

@chrillewoodz
Copy link

Where can we track this? I need this available asap.

@hongbo-miao
Copy link

@chrillewoodz I guess this one now: #2749

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet