Sha256: b9ef890e1dc266da6fb3fb4595ee93c47e06c10d1860e0ab71ea90949b8c7d0b

Contents?: true

Size: 1.55 KB

Versions: 26

Compression:

Stored size: 1.55 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
"use strict";

const sortByIndex = (a, b) => {
	return a.index - b.index;
};

const sortByIndex2 = (a, b) => {
	return a.index2 - b.index2;
};

class ChunkModuleIdRangePlugin {
	constructor(options) {
		this.options = options;
	}

	apply(compiler) {
		const options = this.options;
		compiler.hooks.compilation.tap("ChunkModuleIdRangePlugin", compilation => {
			compilation.hooks.moduleIds.tap("ChunkModuleIdRangePlugin", modules => {
				const chunk = compilation.chunks.find(
					chunk => chunk.name === options.name
				);
				if (!chunk) {
					throw new Error(
						`ChunkModuleIdRangePlugin: Chunk with name '${options.name}"' was not found`
					);
				}

				let chunkModules;
				if (options.order) {
					chunkModules = Array.from(chunk.modulesIterable);
					switch (options.order) {
						case "index":
							chunkModules.sort(sortByIndex);
							break;
						case "index2":
							chunkModules.sort(sortByIndex2);
							break;
						default:
							throw new Error(
								"ChunkModuleIdRangePlugin: unexpected value of order"
							);
					}
				} else {
					chunkModules = modules.filter(m => {
						return m.chunksIterable.has(chunk);
					});
				}

				let currentId = options.start || 0;
				for (let i = 0; i < chunkModules.length; i++) {
					const m = chunkModules[i];
					if (m.id === null) {
						m.id = currentId++;
					}
					if (options.end && currentId > options.end) break;
				}
			});
		});
	}
}
module.exports = ChunkModuleIdRangePlugin;

Version data entries

26 entries across 25 versions & 8 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.18.0 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.18.2 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.16.1 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.15.2 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.18.4 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.18.1 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.14.0 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
tang-0.2.1 spec/tang_app/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
tang-0.2.0 spec/tang_app/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
tang-0.1.0 spec/tang_app/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
tang-0.0.9 spec/tang_app/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
enju_library-0.3.8 spec/dummy/node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js
jester-data-8.0.0 node_modules/webpack/lib/optimize/ChunkModuleIdRangePlugin.js