pirelenito / git-revision-webpack-plugin

🏗 Webpack plugin that generates VERSION and COMMITHASH files during build
https://www.npmjs.com/package/git-revision-webpack-plugin
MIT License
358 stars 48 forks source link

output.filename as function doesn't work #39

Closed ndesorden closed 5 years ago

ndesorden commented 5 years ago

With latest webpack (4.26.1) using options.filename with a function throws error when adding GitRevisionPlugin to plugins array

return {
        entry: {
            app: `./${SRCFOLDER}/entrypoints/main.js`
        },
        output: {
            filename: () => 'test.js' 
            // with example function from docs same error
            filename: (chunkData) => {
                 return chunkData.chunk.name === 'main' ? '[name].js': '[name]/[name].js';
           },
        },
 ...

        plugins: [
            new GitRevisionPlugin({
                versionCommand: 'describe --always --tags --abbrev=0'
            }),

Console output:

ERROR in chunk app [entry]
() => 'test.js'
path.replace is not a function
error Command failed with exit code 2.

Other relevant information: webpack version: 4.26.1 Node.js version: 8.11.2 Operating System: windows 10 Additional tools:

ndesorden commented 5 years ago

Something like this fix the issue:


    compilation.mainTemplate.hooks.assetPath.tap('asset-path', (filename, chunkData) => {
      return (typeof filename === 'function'
        ? filename(chunkData)
        : filename).replace(replacePattern, data);
    })
pmeinhardt commented 5 years ago

I ran into the same issue after upgrading mini-css-extract-plugin from 0.5.0 to 0.8.0. Thanks for having taken the time to fix this issue already @njbmartin 🙇