导入/捆绑 Bootstrap 5 或 Popper.js 与 Gulp 4 生成 LICENSE.js 文件?

Importing / bundling Bootstrap 5 or Popper.js with Gulp 4 generates LICENSE.js file?

我在 Bootstrap 5 项目上使用 Gulp 4 和 Webpack 5,当我捆绑我的脚本时,Gulp 生成一个 bundle.js(如预期的那样)但它也会生成一个 bundle.js.LICENSE.js 文件。

我在我的构建任务中看不到任何会创建它的内容。

似乎只有当我import 'bootstrap'import Popper from 'popper.js/dist/umd/popper'时才会这样。

有没有办法禁止生成那个 LICENSE 文件?我猜 Bootstrap 5 js 中有些东西强制 Gulp 或 Webpack 创建该文件(?)

如有任何想法,我们将不胜感激。这是我的构建脚本任务:

// Build Scripts Task
const buildScripts = (mode) => (done) => {
  let streamMode;
  if (mode === 'development') {
    streamMode = require('./webpack/config.development.js');
  } else if (mode === 'production') {
    streamMode = require('./webpack/config.production.js');
  } else {
    streamMode = undefined;
  }
  
  ['development', 'production'].includes(mode) ? pump([
    gulp.src(srcPath('js')),
    vinylNamed(),
    webpackStream(streamMode, webpack),
    gulpSourcemaps.init({ loadMaps: true }),
    through2.obj(function (file, enc, cb) {
      const isSourceMap = /\.map$/.test(file.path);
      if (!isSourceMap) {
        this.push(file);
      }
      cb();
    }),
    gulpBabel({
      presets: ['@babel/preset-env'],
    }),
    ...((mode === 'production') ? [gulpUglify()] : []),
    gulpSourcemaps.write('./'),
    gulp.dest(distPath('js')),
    browserSync.stream(),
  ], done) : undefined;
};

Webpack 用于优化文件的插件称为 Terser,它具有将与特定模式匹配的内联注释提取到外部文件(默认情况下是您看到的许可证模式)的选项。

https://webpack.js.org/plugins/terser-webpack-plugin/

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          //...
          extractComments: true
        },
      }),
    ],
  },
}

By default extract only comments using /^**!|@preserve|@license|@cc_on/i regexp condition and remove remaining comments. If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE.txt. The terserOptions.format.comments option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted.

检查您的 config.production.js webpack 文件,看看是否在其中使用了这些选项。不过它确实默认为 true