Repository: webpack/webpack
File: lib/WebpackOptionsApply.js (JavaScript)

Code before:
					}).apply(compiler);
					break;
				}
				case "total-size": {
					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
					const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin");

					new OccurrenceChunkIdsPlugin({
						prioritiseInitial: false
					}).apply(compiler);
					break;
				}
				default:
					throw new Error(
						`webpack bug: chunkIds: ${chunkIds} is not implemented`
					);
			}
		}
		if (options.optimization.nodeEnv) {
			const DefinePlugin = require("./DefinePlugin");

			const defValue = JSON.stringify(options.optimization.nodeEnv);

			new DefinePlugin({
				"process.env.NODE_ENV": defValue,
				[`${options.output.importMetaName}.env.NODE_ENV`]: defValue
			}).apply(compiler);
		}
		if (options.optimization.minimize) {
			for (const minimizer of options.optimization.minimizer) {
				if (typeof minimizer === "function") {
					/** @type {WebpackPluginFunction} */
					(minimizer).call(compiler, compiler);
				} else if (minimizer !== "..." && minimizer) {
					minimizer.apply(compiler);
				}
			}
		}

		if (options.performance) {
			const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");

			new SizeLimitsPlugin(options.performance).apply(compiler);
		}

		new TemplatedPathPlugin().apply(compiler);

		new RecordIdsPlugin({
			portableIds: options.optimization.portableRecords
		}).apply(compiler);


Review comment (suggestion):
I’m not sure if we really need an ImportMetaEnvPlugin. It seems sufficient to simply add import.meta.env.xxx keys for all process.env.xxx variables. 
If we introduce ImportMetaEnvPlugin, it would replace every import.meta.env reference at build time — even those that don’t exist during the build but might exist at runtime.

Code after:
					}).apply(compiler);
					break;
				}
				case "total-size": {
					// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
					const OccurrenceChunkIdsPlugin = require("./ids/OccurrenceChunkIdsPlugin");

					new OccurrenceChunkIdsPlugin({
						prioritiseInitial: false
					}).apply(compiler);
					break;
				}
				default:
					throw new Error(
						`webpack bug: chunkIds: ${chunkIds} is not implemented`
					);
			}
		}
		if (options.optimization.nodeEnv) {
			const DefinePlugin = require("./DefinePlugin");

			const defValue = JSON.stringify(options.optimization.nodeEnv);

			new DefinePlugin({
				"process.env.NODE_ENV": defValue,
				"import.meta.env.NODE_ENV": defValue
			}).apply(compiler);
		}
		if (options.optimization.minimize) {
			for (const minimizer of options.optimization.minimizer) {
				if (typeof minimizer === "function") {
					/** @type {WebpackPluginFunction} */
					(minimizer).call(compiler, compiler);
				} else if (minimizer !== "..." && minimizer) {
					minimizer.apply(compiler);
				}
			}
		}

		if (options.performance) {
			const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");

			new SizeLimitsPlugin(options.performance).apply(compiler);
		}

		new TemplatedPathPlugin().apply(compiler);

		new RecordIdsPlugin({
			portableIds: options.optimization.portableRecords
		}).apply(compiler);