You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to change a string in the templateUrl property of the Angular component decorator. For that I'm using custom-webpack builder and string-replace-loader. For test I created a simple project that contains only app.component. Minimal reproduction is available below.
Description
My replaced by string-replace-loader templateUrl string is not included in the build result, but instead the default app.component.html content is included.
Interesting:
When mergeRules.module.rules is append I see my console.log in a replace function and understand that the string find and needs to be replaced.
When it's prepend the already converted template gets into the loader and obviously it does not find the correct string to replace.
When I add enforce: "pre" to the rule object the result will pretty similar as for append
Minimal Reproduction
I have a pretty small piece of code in webpack.config.js, so, here it is:
first way, with replace function and a console for smth like "debug":
module.exports={module: {rules: [{// enforce: 'pre',test: /\.component.ts$/,use: {loader: 'string-replace-loader',options: {search: /([\w-]+)\.component\.html/,replace: function(match,reg,offset,string){console.log('component content as a string',string);return'changed.component.html'}}},}]}};
to build a project use ng build command it will build an application in development mode for more convenience
Expected Behavior
The content of dist/main.js file and specifically it's component part is created with the content of replaced in templateUrl path to template, for now the content is default app.component content
Closing since this is not related to the actual custom-webpack package.
Angular components are proceeded before Webpack runs loader. Because Angular uses thisCompilation compiler hook to setup its AOT program. Component files are read through ts.CompilerHost.getSourceFile which delegates file reads to enhanced-resolved, which then uses native fs calls, as fs.open, etc.
So you may want to augment getSourceFile with your native implementation, this will call the original implementation, but update the source file content with what you need.
Hi!
I'm trying to change a string in the
templateUrl
property of the Angular component decorator. For that I'm usingcustom-webpack
builder andstring-replace-loader
. For test I created a simple project that contains only app.component. Minimal reproduction is available below.Description
My replaced by
string-replace-loader
templateUrl string is not included in the build result, but instead the default app.component.html content is included.Interesting:
When
mergeRules.module.rules
isappend
I see my console.log in a replace function and understand that the string find and needs to be replaced.When it's
prepend
the already converted template gets into the loader and obviously it does not find the correct string to replace.When I add
enforce: "pre"
to the rule object the result will pretty similar as forappend
Minimal Reproduction
I have a pretty small piece of code in webpack.config.js, so, here it is:
first way, with replace function and a console for smth like "debug":
and even less but still not working
in angular.json
and two small html templates:
app.component.html
changed.app.component.html
reproduction repo is available here
ng build
command it will build an application in development mode for more convenienceExpected Behavior
The content of
dist/main.js
file and specifically it's component part is created with the content of replaced in templateUrl path to template, for now the content isdefault app.component content
Environment
PS: This problem looks very similar to this one
PSS: I do not rule out that this is not a bug at all, but my crooked hands :) I will be glad to receive advice or comments.
Thank you for your time
Best regards Gennady
The text was updated successfully, but these errors were encountered: