Files
graylog2-server/graylog2-web-interface/webpack/UniqueChunkIdPlugin.js
Dennis Oelkers 6a8994740f Updating to Webpack 5. (#11626)
* Updating to Webpack 5.

* Adding explicit dependency for `buffer`.

* Updating vendor module ids.

* Logging error when loading component async fails.

* Adding root directory of plugin as parameter to `PluginWebpackConfig`.

* Removing unused loaders.

* Revert "Removing unused loaders."

This reverts commit 7ec4d8e0717f0a3eb35c8db829fd91b4d7f8cb03.

* Slight updates of webpack packages.

* Disabling linter hints.

* Adjusting tests.

* Updating terser plugin, removing obsolete source map option.

* Fixing import order.

* Readding `HashedModuleIdsPlugin`.

* Updating yarn lockfile.

* Updating vendor module ids.

* Removing explicit loader references.
2021-12-02 12:11:53 +01:00

47 lines
1.6 KiB
JavaScript

/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
const crypto = require('crypto');
const pluginName = 'UniqueChunkIdPlugin';
class UniqueChunkIdPlugin {
// eslint-disable-next-line class-methods-use-this
apply(compiler) {
const randomId = crypto.randomBytes(4).toString('hex');
// eslint-disable-next-line prefer-template
const prefix = randomId + '-';
compiler.hooks.compilation.tap(pluginName, (compilation) => {
compilation.hooks.optimizeChunkIds.tap(pluginName, (chunks) => new Set([...chunks].map((chunk) => {
// eslint-disable-next-line prefer-template, no-param-reassign
if (chunk.id && chunk.id.startsWith && chunk.id.startsWith(prefix)) {
return chunk;
}
// eslint-disable-next-line no-param-reassign
chunk.id = prefix + chunk.id;
// eslint-disable-next-line prefer-template, no-param-reassign
chunk.ids = chunk.ids.map((id) => randomId + '-' + id);
return chunk;
})));
});
}
}
module.exports = UniqueChunkIdPlugin;