-
Notifications
You must be signed in to change notification settings - Fork 12k
Rebuild speed and style workflows (feedback) #2956
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
hey angular cli team. looks all amazing. we are in the same situation. we have a custom gulp workflow. its crazy fast compared to angular-cli. app reload for js/ts changes is fine but styles should be injected like browser sync does it. is this on the roadmap? |
Any updates ? |
I've been working on this for past few days - exploring alternatives and tinkering with various options. It would be so much easier if documentation was better... I cleaned up some stuff, improved few things and got from 6-8 sec reload time to about 4 seconds. This is using SystemJS and serving all files from Main reason is rxjs - Angular heavily depends on it and it's loading stuff from library everywhere. These 400+ requests in the image above are for rxjs stuff (almost 80% of them). The next thing I did was to bundle all angular modules, so they load rxjs from memory, instead of the network. That improved things somewhat, but my code was also calling rxjs alot. So I bundled rxjs too: Loading is faster and XHR requests are just for app code (almost 5x less). I ended up using rollup for angular and systejs-builder for rxjs - couldn't do better with my trial&error approach - configuring systemjs is still most painfull thing is all this process. I had to use System API to load modules from bundle, couldn't figure out how to set it up with Bundling framework code seams to be the best approach. I've seen it in some other projects and seeds, and it's working well. Perhaps someone can do it for CLI too, using webpack. I believe this workflow would be beneficial. I'm not sure how things work internally with webpack, does it use I still have few things to do for my dev workflow. My goal is to get to about 1 second full reload times (without HMR). I think I can get there with http2. Also, to make it plug-and-play-nicely with CLI. If it turns out webpack isn't as fast, maybe this can become CLI add-on some day (; |
wow this amazing, I feel really stress if everything just slow in current angular CLI version. If you have a big project, that is a disaster. I vote for this solution |
It seams things can't get much better then my last setup (Image 2). At least not without AoT. Image 3 shows the log of the same project built with I tried to implement HMR and managed to connect to dev server, notify systemjs and reload modules as they are compiled, but didn't figure out what to do to update app itself yet. |
Heya @sasxa, thank for the the benchmarks and setup details. I'll address some of the issues raised here but am still closing this particular issue because it's essentially a dupe of #1980 as far as it being actionable goes, although your post was more informational and exploratory.
We've already merged some changes that dramatically affect build times and for the foreseeable future the plan is to make our Webpack-based builds as fast as possible. Cheers for taking the time to give such detailed feedback, and if you want to share your results with more people I'd really advise posting it in #1980 so that everyone in the rebuild speed discussion gets it. |
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 just finished rewriting my old gulp build tasks to work with CLI. Results are... interesting :) #1980
CLI
Gulp
Webpack is,, of course, much better at optimizing assets, while gulp can be optimized for really fast incremental builds. At this time I didn't do anything with vendor files, I'm just serving them with BrowserSync directly from
node_modules
- that's why there are so many requests and why load times are high. I also didn't bother with code splitting, AoT and other stuff Webpack and CLI already do - I just want fast dev builds; I'm definitely gonna use CLI for that stuff.This is done at the same time in two terminal windows - first running Gulp watch and serving files with BrowserSync, second running webpack-dev-server. If you want to try it yourself, you can find full logs and files I used here: (Gist). Build works with CLI project with some modification - for
index.html
andsystem.config.js
I used files from docs/quickstart and modified them to fit my project. Only other thing needed to make it work is to removeimport './polyfills.ts';
from 'src/main.ts`.OK, now the reason I'm writing this is to share what I learned while trying to make this work, hopefully it will be useful and help improve CLI.
Styling
src/styles/
folder where all my.styl
files are and I'm importing them fromsrc/styles.styl
with@import 'styles/defaults'
. I also havesrc/styles/variables.styl
where I@import "C:/.library/styl/mixins.styl"
... It would be nice if we had access tostylus
to extend it, like I'm doing:Same goes for other modules (html-minifier, autoprefixer, csso...). Since I couldn't setup paths where stylus looks for imports, I had to use
@import '../../styles/variables'
in my component styles, which I had to remove in order to process styles with Gulpfile.replace(/@import\s+'(?:\.\.\/)+/gmi, '@import \'')
.Another nice feature would be to have separate file for inline styles, that would be injected directly in
<head>
while the rest are loaded normally, via<link>
. I think I saw something like this in early versions with--mobile
and/or--universal
... I saw some improvements with styles workflows on master branch, nice! Hope to see more (;Dev builds
Concerning module resolution, I'm using
"compilerOptions.baseUrl": "."
path mapping so I can useimport {...} from 'app/core/service'
instead ofimport {...} from '../../../../app/core/service'
in my components. Might be useful to be there by default? I saw some issues/PRs/commits withimport {...} from '@shared'
- not sure what's the status of that, but aliasing app root is really useful for me.While building my gulp tasks I noticed that rebuilding typescript files seams to be main reason for high rebuild times. I chose to use settings that give me fastest results
I'm not bundling files, my components/services/modules etc. are in separate files. This allows me to utilize gulp's caching, so it will only process changed files:
I used
"isolatedModules": true,
compiler option to make this work. TypeScript now Unconditionally emit imports for unresolved files., which also speed things up.I'm injecting everything in js file - templates, styles, sourcemaps. It's not ideal, and sourcemaps are not precise, but I usually know what I'm doing, so most of the time I can find errors quickly. And if not, I can always use different options to track down bugs. With 50-250ms rebuild times I work differently then when I have to wait 5-15s... For production builds and various optimizations I really don't mind waiting 30-90s.
While I don't think something like this should be default option for CLI, perhaps there are some things you could turn off, or do differently to speed things up. Maybe provide some flag to turn off some safety checks, not bundle everything each time and such. I'm not that familiar with webpack to offer any suggestions, but maybe something I mentioned can help (;
Finally, just to mention the dreadful systemjs... The way I have structured my modules and components is really, really painful to setup with systemjs. In fact, making it work took me almost as long as everything else... It was the reason why I was happy CLI switched to webpack. Working with CLI is soo much easier. If (or when!) CLI was 10x faster I would gladly forget everything about systemjs. Forever (:
The text was updated successfully, but these errors were encountered: