-
Notifications
You must be signed in to change notification settings - Fork 12k
@ngtools/webpack: Misleading documentation & Config Refactor Proposal #9063
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
It is true that the loader can be used alone, but that is more an artifact of backwards compatibility than a feature. It was there in the early versions, we don't use it, but didn't remove it prior to 1.x. It is not a feature we plan on developing further either as it is a very limited form of TS compilation. Functionality wise the loader is meant to communicate with the plugin. The plugin is the one doing the real full-features compilation. The loader waits for the plugin to perform TS compilation, and retrieves the artifacts. The two are needed due to the overall Webpack architecture. There are code transformations performed by the plugin in both JIT and AOT so it is needed due to that. Type checking overall also needs the plugin. We don't intend the loader to be used with other plugins, or other loaders to work with the plugin. Regarding the code being held in memory, that is generally true of any webpack based setup. The only setups that save artifacts on disk are the ones that cache the intermediate webpack format, which isn't overall usable outside webpack. For that reason I don't think it's really worth mentioning that the artifacts are held in memory. There is a request to keep the generated code around somewhere for debugging purposes though: #6203. I hope that answers your questions. |
@filipesilva thank you for the explanation. Are there other code transformations performed by the compiler in JIT other than replacing What tripped me up about the code being generated in memory is the compiler ignores the if (PRODUCTION) {
const AppModuleFactory = require('path/to/genDirOption/app.module.factory');
const platformBrowser = require('@angular/platform-browser');
platformBrowser().bootstrapModule(AppModuleFactory);
} I think it is worth mentioning these things, even just briefly, in the docs. |
I noticed the |
We have a couple of code transformations that we apply according to the platform and JIT/AOT mode. You can find
It's mostly resource replacement, bootstrap replacement, decorator removal, and exporting extra stuff. But it's still a fair number of things. On the topic of the Regarding Would you be interested in making a PR that mentions how the bootstrap is replaced? There are two places I think should contain this information and mostly in the same form: |
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version. If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. |
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 think the docs for
skipCodeGeneration
are wrong? According to the docs,However, rewriting the Urls seems to be the responsibility of the
@ngtools/webpack
loader, which can be used standalone without the AngularCompiler as long as atsConfigPath
is specified.So it seems to me the
@ngtools/webpack
loader is equivalent to a typescript compiler plus the ability to rewritetemplateUrl
andsyleUrls
.This brings me to 2 things,
In development it makes more sense to use the JIT compiler. Is there any reason you would want to use the compiler plugin in development with
skipCodeGeneration
set totrue
as opposed to just not using the plugin at all?If the
@ngtools/webpack
loader is responsible for compiling the typescript then I think any options that affect the typescript compilation process should be moved to the loader. For example, if I am only using the loader in development then there is no way for me to enable type checking unless I also include the plugin and settypeChecking
totrue
in the plugin options.I believe it is good to use the same loaders for development and production builds because different loaders may behave slightly different. For example, I could use the
ts-loader
and theangular2-template-loader
in development and not use the@ngtools/webpack
loader at all but theangular2-template-loader
is able to resolve files without a file extension (maybe using Webpack resolve config?) where as the@ngtools/webpack
will fail without the file extension. All of a sudden when you build for production you will get an error likeCouldn't resolve resource foo.template from C:/path/to/project/app/components/foo/foo.component.ts
You can probably imagine how confusing this might be.
Also, I think the docs should mention that the generated code is held in memory along side the source code because this is something that could easily trip up people trying to use the plugin. It might also be good to include an option to write the generated factories to disk somewhere for debugging purposes.
One last thing, thank you to everyone working on these Webpack integrations!
The text was updated successfully, but these errors were encountered: