-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Conversation
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. |
Hi @devCrossNet, could you rebase this PR? It's obviously on top of previous commits, so there is some problem with it. Thanks! |
0baf833
to
5989dd2
Compare
CLAs look good, thanks! |
@hansl I rebased the branch |
@@ -14,7 +14,7 @@ module.exports = { | |||
|
|||
beforeInstall: function() { |
There was a problem hiding this comment.
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 :)
@devCrossNet guidelines to update an existing project to universal will be helpful. |
5989dd2
to
34ab9ad
Compare
d5fac08
to
f2aa290
Compare
0413923
to
9a2a0df
Compare
AoT is currently not working with universal. |
9a2a0df
to
c23b869
Compare
@devCrossNet what about lazy routing support ? |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
7639230
to
611f337
Compare
611f337
to
516d576
Compare
test: /\.js$/, | ||
loader: 'source-map-loader', | ||
exclude: [ | ||
path.resolve(projectRoot, 'node_modules/rxjs'), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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$/, |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what and why
There was a problem hiding this comment.
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', () => {}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
@@ -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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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? |
@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. |
516d576
to
98fe28f
Compare
@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
98fe28f
to
b155283
Compare
@kuldeepkeshwar I don't know. I have to talk about it with the team |
Closing this PR to master, as this is being tracked/managed in a separate branch. |
@Brocco can you put the new link here so we can track? thanks |
Where can we track this? I need this available asap. |
@chrillewoodz I guess this one now: #2749 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
add the possibility to scaffold a universal project with --universal