webpack-merge-and-include-globally icon indicating copy to clipboard operation
webpack-merge-and-include-globally copied to clipboard

Supporting [hash] during production build

Open jameshydeamg opened this issue 5 years ago • 18 comments

Hi,

I noticed this doesn't seem to support [hash] during a production build. This would be really useful for us, is there any chance this could be added?

jameshydeamg avatar Oct 01 '18 15:10 jameshydeamg

do you mean reprocessing only files that changed? can you introduce me to hashing?

markshapiro avatar Oct 01 '18 17:10 markshapiro

The hash could be used for the manifest.json file.

aliechti avatar Nov 07 '18 14:11 aliechti

added hash option (true/false) to append hash before file extension, using rev-hash library

markshapiro avatar Nov 11 '18 17:11 markshapiro

The file has now the hash before the extension. But there is no entry in the manifest.json file.

This problem relates to #11

aliechti avatar Nov 19 '18 13:11 aliechti

@markshapiro I have same problem. There is no entry in manifest.json file.

zhanghuanchong avatar Nov 28 '18 16:11 zhanghuanchong

It seems adjusting the plugin's priority to higher is able to add files to manifest.json, but both of the file names are hashed:

"build/app-s29a0wlk.js": "build/app-s29a0wlk.js"

zhanghuanchong avatar Nov 29 '18 03:11 zhanghuanchong

i see the hash option ,but how to use it at vue cli3 scaffold

Insua avatar Dec 12 '18 06:12 Insua

@Insua is there an option to use general webpack plugins in vue cli3? if not I can distill the file transform code from webpack code, so that the merge logic could be reused in different bundlers.

markshapiro avatar Dec 13 '18 15:12 markshapiro

vue cli3 can use generally webpack config,but I do not know how to inject js file to index.html

Insua avatar Dec 14 '18 00:12 Insua

@zhanghuanchong I found temporary solution here: https://github.com/webpack-contrib/copy-webpack-plugin/issues/104

new ManifestPlugin({
    map: (file) => {
        if (process.env.NODE_ENV === 'production') {
            file.name = file.name.replace(/(\-[a-f0-9]{10})(\..*)$/, '$2');
        }
        return file;
    },
}),

markshapiro avatar Dec 14 '18 14:12 markshapiro

fixed the double names, the plugin appears not to be working with version 1 ofwebpack-manifest-plugin, v2 works.

markshapiro avatar Dec 16 '18 03:12 markshapiro

@Insua will this help? https://stackoverflow.com/questions/45145448/including-external-script-in-vue-js-template

markshapiro avatar Dec 16 '18 15:12 markshapiro

The hash option generates now a correct entry in my manifest file. But it does ignore the manifest plugin configuration for the hash placement.

Example:

{
  "build/script.js": "/build/script-3ce06daa80.js",
}

aliechti avatar Feb 20 '19 10:02 aliechti

@thejahweh you mean when you configure yourself the hash ending in the manifest plugin? are you using webpack-manifest-plugin v2?

markshapiro avatar Feb 21 '19 14:02 markshapiro

Yes I'm using [email protected].

But I'm using Symfony Encore for the configuration, so I really don't know what configureFilenames does under the hood, maybe they'r using another plugin for this?

.configureFilenames({
    js: '[name].js?[contenthash:16]',
    css: '[name].css?[contenthash:16]',
    images: 'images/[name].[ext]?[hash:16]',
    fonts: 'fonts/[name].[ext]?[hash:16]'
})

aliechti avatar Feb 27 '19 08:02 aliechti

@thejahweh shall I then give option to use custom hash for each file? or maybe the right solution is to automatically recognize the configuration of manifest plugin and use it? do you know maybe the configuration property that is used in the manifest plugin?

markshapiro avatar Mar 04 '19 19:03 markshapiro

As far as I see, this has to do with the Webpack loaders.

For example: https://github.com/webpack-contrib/file-loader You can see that there is a options name configuration, which is used to save the file with a pre defined naming scheme.

aliechti avatar Mar 06 '19 09:03 aliechti

Hi, why is the issue still open? For me everything is fine with the hash option:

content of mainfest.json "components.js": "/dist/components-bb1cea7358.js",

ruettenm avatar Mar 25 '20 09:03 ruettenm