简体   繁体   English

使用 angular cli 项目在块中插入自定义属性

[英]Insert custom attribute in chunks with angular cli project

i have a angular v11 solution with CLI.我有一个带有 CLI 的 angular v11 解决方案。 I've added this line in the angular.json to be able to extend the webpack with my custom implementation我在 angular.json 中添加了这一行,以便能够使用我的自定义实现扩展 webpack

 "customWebpackConfig": {
   "path": "config/webpack.dev.js",
   "replaceDuplicatePlugins": false
 }

And this is my custom webpack这是我的定制 webpack

 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
 module.exports = {
    plugins: [
        new HtmlWebpackPlugin(),
        new ScriptExtHtmlWebpackPlugin({
            custom: {
                test: /\.js$/,
                attribute: 'data-ot-ignore'
            }
        }),
    ]
};

I want to add custom attribute in the index.html after the build is done.构建完成后,我想在 index.html 中添加自定义属性。 But the implementation above is not working.但是上面的实现不起作用。

This is what i want:这就是我要的:

在此处输入图像描述

is it possible to do it?有可能吗? Thank you!谢谢!

I've ended up using IndexTransform我最终使用了IndexTransform

// add attribue to skip oneTrust blocking script
  indexHtml = indexHtml.replace('src="runtime', 'data-ot-ignore src="runtime');

return indexHtml;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM