首页 > 解决方案 > 如何从特定捆绑文件名中删除哈希,在 Angular 10 中创建产品构建

问题描述

我正在尝试使用 angular 10 创建一个 chrome 扩展。在执行 ng build --prod 时,哈希被附加到 background.js 捆绑文件中,如“background.6f24e1b6d7ac365xxxxxx.js”。

有没有一种方法可以在执行 ng build --prod 时仅删除此捆绑包的哈希?

我可以做的一件事是使用自定义捆绑文件名 angular-cli中提到的节点重命名此文件。我希望通过 webpack 或任何其他方式来实现这一点。

custom.webpack.config文件(需要将 manifest.json 复制到 dist 文件夹并将 background.ts 转换为 background.js,因为它没有在 Angular 应用程序中使用)

const CopyWebPackPlugin = require('copy-webpack-plugin');
const path = require('path');

module.exports = {
    plugins: [
        new CopyWebPackPlugin({
            patterns:[
            {from:'manifest.json', to:''}            
            ]
        }),
      ]
    entry: { background: 'src/background.ts' } 
}

用于谷歌浏览器扩展的manifest.json文件

{
    "name": "Javascript",
    "version": "1.0",
    "description": "javascript",
    "key": <chrome extension key>,
    "manifest_version": 2,
    "browser_action": {
        "default_popup": "signin.html"
    },
    "background": {
        "scripts": [
            "./background.js"
        ]
    },
    "permissions": [
        "identity"
    ]
}

背景.ts文件

This will contain code for google chrome extension in typescript or javascript

注意:我只希望这两个包 runtime.js 和 background.js。我想在 main.xxxxxxxxxx.js、polyfills.xxxxxxxxxx.js、polyfills-es5.xxxxxxxxxx.js 等其他包中继续进行哈希处理。

标签: angularwebpackgoogle-chrome-extensionwebpack-4angular10

解决方案


推荐阅读