-
Notifications
You must be signed in to change notification settings - Fork 12k
Allow directTemplateLoading to be set from angular.json #15861
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
This should be an option in the custom webpack builder and not the CLI. |
The |
That's a good point. If you're not using a custom builder, then setting it to false would only cause the build to fail. 👍
I'm having a hard time working out how that's currently possible. In Lines 94 to 99 in 95776fe
It also adds the
Line 109 in 95776fe
Line 128 in 95776fe
I'm not too familiar with the codebase, so perhaps I've missed something. Would you be able to show an example of how to modify the options for |
@clydin Are you able to provide an example of how to modify the options for |
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. |
🚀 Feature request
Command (mark with an
x
)Description
The
AngularCompilerPlugin
allows templates to be loaded directly, bypassing any loaders configured in the webpack config. The default value of this option isfalse
.The Angular CLI creates an instance of the
AngularCompilerPlugin
and sets this option totrue
, with no way of overriding this behavior.angular-cli/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/typescript.ts
Line 94 in e8cdfa6
Setting this to
true
made sense when there was no way to customize the webpack config. However, now that CLI Builders are officially supported, it will become more common for builders like@angular-builders/custom-webpack
to be used to customize the webpack configuration. But withdirectTemplateLoading
being hard-coded totrue
, there is no way to customize the webpack configuration to allow a loader to manipulate a component's template.Describe the solution you'd like
Let the
directTemplateLoading
option be set in theangular.json
file. For example:Describe alternatives you've considered
This idea has been raised before in a couple of issues, but both were closed with workarounds or hacks. Since CLI Builders are now officially supported, I feel that a proper solution is required.
Use
template
and inline loaders#14855 (comment) suggests using
template
and specifying the loaders in the require statement instead of usingtemplateUrl
.Manually specifying the same loaders for every component template is not maintainable.
Hack the webpack config
#14534 (comment) states that a hack is required to set
directTemplateLoading
:The "above method" is to search through the plugins in the webpack config and find the
AngularCompilerPlugin
, get it's options, change thedirectTemplateLoading
value to false, create a new instance of the plugin with the modified options and replace the original plugin in the webpack config. Very hacky.Use
template
with loaders in the webpack configSimilar to the outcome of #14855, you can:
@types/node
."node"
to thetypes
property of the tsconfig file.templateUrl: './foo.component.html
totemplate: require('./foo.component.html')
and the custom loaders specified in the webpack config will be used. But this requires you to make changes to the way the component's template is specified by default, which is easy to forget to do. That's just asking for problems because forgetting to change
templateUrl
totemplate
means it won't be passed through the custom loaders.In addition to that, the Angular Language Service complains that "Component 'FooComponent' must have a template or templateUrl".
Given the choice between this and hacking the webpack config to recreate the
AngularCompilerPlugin
, I'd choose hacking the webpack config. 😁The text was updated successfully, but these errors were encountered: