【问题标题】:webpack configuration: remove hash from *.js entry/bundle files nameswebpack 配置:从 *.js 条目/捆绑文件名中删除哈希
【发布时间】:2020-07-17 12:45:25
【问题描述】:

我正在做一个 vue.js 应用程序。

构建后生成一个 js 文件“background.2a548437.js”,而不是我想要的“background.js”。

我正在通过“vue.config.js”文件进行webpack-chain配置。

为了诊断,我正在读取“$vue inspect”的结果,但我没有看到我应该调整哪个参数来从 js 文件中删除哈希。

我确实看到像 'img/[name].[hash:8].[ext]' 这样的模式,但对于 js,它是 'js/[name].js'

您有任何解决方案或线索吗?


背景/原因:

它使用 webpack "^4.0.0" 和 webpack-chain "^6.3.1" 通过 "vue.config.js" 进行配置。

我正在做一个 chrome 插件,它有一个引用“background.js”的静态 manifest.json 文件。

我将深入研究使用正确的“background.[hash].js”文件构建一个 manifest.json 文件的 webpack 但我认为如果我能找到在文件名中禁用哈希的选项会更容易


// vue.config.js

const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    chainWebpack: config => {
        // add your custom entry point
        config
            .entry('background')
            .add('./src/background.ts');
    },
    configureWebpack: {
        plugins: [
            new CopyWebpackPlugin([
                { from: 'manifest.json', to: 'manifest.json', flatten: true },
            ]),
        ]
    }
}

编辑: $vue 检查的结果。它太长了,所以我链接了一个 pastebin https://pastebin.com/fbRzgfhY

【问题讨论】:

    标签: vue.js webpack google-chrome-extension webpack-chain


    【解决方案1】:

    花了这么长时间试图了解 webpack-chain、webpack 及其插件的工作原理后,我在 vue 文档中发现了简单的“filenameHashing”错误:https://cli.vuejs.org/config/#indexpath

    这是我的 vue.config.js 文件内容:

    // vue.config.js
    const CopyWebpackPlugin = require('copy-webpack-plugin');
    
    module.exports = {
        filenameHashing: false, // <=================line that matters
        chainWebpack: config => {
            // add your custom entry point
            config
                .entry('background')
                .add('./src/background.ts');
        },
        configureWebpack: {
            plugins: [
                new CopyWebpackPlugin([
                    { from: 'manifest.json', to: 'manifest.json', flatten: true },
                ]),
            ]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多