From 36b6af9259a50d967075870482efa0917ea5f98f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 13 May 2024 09:48:54 +0200 Subject: [PATCH] fix: Also extract comments for `spdx` license information Signed-off-by: Ferdinand Thiessen --- webpack.common.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/webpack.common.js b/webpack.common.js index d84979f74cdda..aa937719f246d 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -147,6 +147,26 @@ module.exports = { }, optimization: { + minimizer: [{ + apply: (compiler) => { + // Lazy load the Terser plugin + const TerserPlugin = require('terser-webpack-plugin') + new TerserPlugin({ + extractComments: { + condition: /^\**!|@license|@copyright|SPDX-License-Identifier|SPDX-FileCopyrightText/i, + filename: (fileData) => { + // The "fileData" argument contains object with "filename", "basename", "query" and "hash" + return `${fileData.filename}.license${fileData.query}` + }, + }, + terserOptions: { + compress: { + passes: 2, + }, + }, + }).apply(compiler) + }, + }], splitChunks: { automaticNameDelimiter: '-', minChunks: 3, // minimum number of chunks that must share the module