-
Notifications
You must be signed in to change notification settings - Fork 12k
Easy "ng build" improvements to make "platform":"server" work well on Windows & Visual Studio #7903
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
Comments
Hello @SteveSandersonMS,
Thank you for providing an actual use case for this option. When designing the Universal, we found a lot of problems with using a self-contained build (I'll explain in a bit), and couldn't possibly find reasons to provide an option for bundling up. So it was decided to remove the option entirely. Adding the option itself is trivial (as you mentioned), but there is a large cost on the developer and you're turning your project into a minefield. You're basically painting yourself in a corner, for the following reasons:
Given all that, it was significantly dangerous for users for us to not allow self-contained builds. So we decided that there should simply not be an option. Remember that the CLI builds the application bundle, but it's up to the developer to bring their own server. As a result, we do not know how to bundle the backend code (we're not a generic build tool, after all), and I'd like you to consider point 4 above and add a rollup configuration to separate building and bundling the application into 2 separate steps. That being said, if you know what your server is going to be, or if your server can be exclusively in Therefore, I'm personally okay with adding a flag that will build a fully bundled server application, with showing up a warning that the user needs to know what they're doing. This is something though that will need to be discussed internally with our relationship team, as it has a lot of impacts on usability of universal. For frameworks like ASP.Net that do not run within NodeJS as part of the server, this might be good enough and help you move along. |
@hansl - thanks for your feedback! Yes, I totally understand that for Node-based application servers, it's preferable for bundles not to be self-contained, since developers have no choice but to deploy What's the best way to proceed with this? Do you want me to send a PR? I'm very happy to do so if that would help. Or given that the key thing is more about designing how this should appear and be described in help text, is it something you'd prefer to do yourself?
I understand that's technically possible, but we already have templates with a working Webpack config, and people get troubled about how complex it seems to them. The central value proposition around moving to an Angular CLI-based template is to reduce the number of pieces. If we have to introduce a further layer of Webpack/Rollup on top of this, that doesn't really achieve the goal. Our target market includes developers who are totally new to all these technologies, so every moving part is a real cost. |
FYI. I talked to the concerned parties and we decided internally that having an additional flag for this isn't a problem. It will only affect server applications, and default to false. Thinking of along the lines of |
Great to hear it! The name If it's possible for this to be configured in |
This flag allows people who know what theyre doing to bundle the server build together with all dependencies. It should only be used when the whole rendering process is part of the main.ts or one of its dependencies. Fixes angular#7903.
This flag allows people who know what theyre doing to bundle the server build together with all dependencies. It should only be used when the whole rendering process is part of the main.ts or one of its dependencies. Fixes angular#7903.
This flag allows people who know what theyre doing to bundle the server build together with all dependencies. It should only be used when the whole rendering process is part of the main.ts or one of its dependencies. Fixes angular#7903.
This flag allows people who know what theyre doing to bundle the server build together with all dependencies. It should only be used when the whole rendering process is part of the main.ts or one of its dependencies. Fixes #7903.
This flag allows people who know what theyre doing to bundle the server build together with all dependencies. It should only be used when the whole rendering process is part of the main.ts or one of its dependencies. Fixes #7903.
@hansl can you please confirm if this option is still supported? Since 1.5.0 Thank you for the awesome work :) |
This flag allows people who know what theyre doing to bundle the server build together with all dependencies. It should only be used when the whole rendering process is part of the main.ts or one of its dependencies. Fixes angular#7903.
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. |
I work on the ASP.NET team and am looking at changing the default Visual Studio ASP.NET + Angular templates to be based around Angular CLI. One thing that's stopping us right now is issues with publishing and deploying such Angular CLI apps.
Basically, for
ng build
to work well with Universal on Windows/VS, it's essential for it to have an option to produce self-contained builds, i.e., ones that don't rely you to deploynode_modules
to your production server.Why this is needed
Originally, the default official ASP.NET templates for Angular, which have server-side rendering on by default, expected developers to deploy
node_modules
to their production servers. This led to many, many issue reports, because it turns out that from Windows, people cannot deploynode_modules
reliably. This isn't really developers fault. Two basic problems:node_modules
.node_modules
is a process that has you waiting for an hour and very frequently will fail with a network-related error eventually.So in the default ASP.NET Core Angular template, we solved this by changing the default Webpack config not to treat
node_modules
as a Webpackexternal
, causing Webpack to bundle all the server-side rendering dependencies into its single bundle output file. That output file is then large (4MB+) but that's OK: people can reliably deploy one 4MB file, as opposed to 20,000 tiny files. And it's only used server-side - this file is never sent to browsers.Now we'd like to change the default Visual Studio ASP.NET templates for Angular to use Angular CLI, but we can only do this when the resulting projects can be published and deployed reliably. And that means a self-contained build option.
Fortunately, the implementation for this in Angular CLI is pretty much trivial - see below.
Bug Report or Feature Request (mark with an
x
)Versions.
1.4.2
Repro steps.
If you run
ng build
to build an app configured with"platform":"server"
, then observe that the resultingdist
directory's bundle files are not self-contained. That is, they only include the application's own code - they don't include the@angular
code from NPM or any other required packages. The only way it can work at runtime is if you havenode_modules
on your production server, which causes great difficulty in practice as described above.Desired functionality.
Ideally there would be an option for the
"platform":"server"
builds to be self-contained - i.e., can run without anynode_modules
, simply by not telling Webpack to treat those files asexternals
during the build. The use cases is to simplify publishing and deployment, especially on Windows/VS.Mention any other details that might be useful.
This is pretty simple to implement. In server.ts from line 13, we see the Webpack config for
externals
used in server builds. All we need is a build option that disables this, i.e., leads to theexternals
array being left empty. Then Webpack will produce completely self-contained bundles that work correctly withoutnode_modules
being on the production server.One minor complication is that, for some reason, Angular CLI tries to minify (via uglify) the server-side bundle in production, which leads to a build error with self-contained bundles. I recommend that server-side builds should not minify by default, because (1) that will fix the error, and (2) who wants to minify their server-side code anyway? It's much easier to understand/debug unminifed server-side code. If necessary this could be another option, but I really think it would be enough just to avoid minifying server builds altogether.
The text was updated successfully, but these errors were encountered: