xz64 / license-webpack-plugin

Outputs licenses from 3rd party libraries to a file
ISC License
165 stars 51 forks source link

perChunkOutput causes conflict #83

Closed tstibbs closed 3 years ago

tstibbs commented 4 years ago

I want all my licences listed in a single file, so I am configuring the plugin like this:

new LicenseWebpackPlugin({
    perChunkOutput: false
})

However my webpack build log now has multiple occurrences of the following warning (approx one warning per chunk):

WARNING in Conflict: Multiple assets emit different content to the same filename licenses.txt

This suggests webpack isn't happy with something that license-webpack-plugin is doing. Having said that, my licenses.txt does appear to contain everything it should (but that maybe that isn't the case for all scenarios).

xz64 commented 4 years ago

Try adding skipChildCompilers: true to license-webpack-plugin and see if that makes a difference?

tstibbs commented 4 years ago

Well... that does get rid of the warnings, but it also loses three licences from the output file (out of about 53). For my project, the libraries that end up missing from the licenses.txt file are: html-webpack-plugin, css-loader, font-awesome. I'm not quite sure why it's affecting those modules and not others.

If it helps you can see my configuration in context (without the change you suggested above) here: https://github.com/tstibbs/geo-bagging/blob/master/ui/webpack.config.cjs#L86. The file generated (again, without the change you suggested above) can be seen here: https://github.com/tstibbs/geo-bagging/blob/gh-pages/licenses.txt

lights0123 commented 4 years ago

For me, it got rid of css-loader (which would be ideal, because it isn't included in the bundle), but got rid of dependencies incuded via CSS (typeface-open-sans).

xz64 commented 4 years ago

I have tried to enable html webpack plugin, css-loader and font-awesome on a sample project but could not recreate the error message. If I could get a minimal test case for this it would help.

tstibbs commented 4 years ago

The following is the smallest I can come up with. To reproduce the warning it should be sufficient to do npm install && npm run build.

Adding skipChildCompilers does get rid fo the error, but also causes the css-loader licence to be missed from the licenses.txt.

==============================

app.js:

import 'leaflet.locatecontrol/dist/L.Control.Locate.min.css'
import 'sidebar-v2/css/leaflet-sidebar.css'

==============================

webpack.config.js:

const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin

module.exports = {
    entry: './app.js',
    plugins: [
        new MiniCssExtractPlugin(),
        new LicenseWebpackPlugin({
            perChunkOutput: false
        })
    ],
    module: {
        rules: [
            {
                test: /\.css$/i,
                use: [MiniCssExtractPlugin.loader, 'css-loader']
            }
        ]
    }
}

==============================

package.json:

{
    "private": true,
    "devDependencies": {
        "css-loader": "^4.2.2",
        "license-webpack-plugin": "^2.3.0",
        "mini-css-extract-plugin": "^0.11.0",
        "webpack": "^4.44.1",
        "webpack-cli": "^3.3.12"
    },
    "dependencies": {
        "leaflet.locatecontrol": "^0.72.0",
        "sidebar-v2": "^0.4.0"
    },
    "scripts": {
        "build": "npx webpack"
    }
}
xz64 commented 3 years ago

Thanks for this test case. It helped a lot while fixing it. It is fixed in v2.3.4 now

xz64 commented 3 years ago

Reopening this issue as the fix caused another issue (issue #89) The change is reverted in v2.3.5

xz64 commented 3 years ago

@silverwind I have fixed this in v2.3.6. Let me know if you see any issues.

xz64 commented 3 years ago

@tstibbs Please try in v2.3.7. There was one bug in v2.3.6 that prevented it from working on webpack 4.

tstibbs commented 3 years ago

@xz64 tested with 2.3.9 (the latest at this point) and your change seems to have fixed the error for me and everything still seems to be working - thank you very much.