123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- "use strict";
- const { ConcatSource } = require("webpack-sources");
- const RuntimeGlobals = require("../RuntimeGlobals");
- const Template = require("../Template");
- const propertyAccess = require("../util/propertyAccess");
- const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
- class ModuleLibraryPlugin extends AbstractLibraryPlugin {
-
- constructor(options) {
- super({
- pluginName: "ModuleLibraryPlugin",
- type: options.type
- });
- }
-
- parseOptions(library) {
- const { name } = library;
- if (name) {
- throw new Error(
- `Library name must be unset. ${AbstractLibraryPlugin.COMMON_LIBRARY_NAME_MESSAGE}`
- );
- }
- return {
- name: (name)
- };
- }
-
- renderStartup(
- source,
- module,
- { moduleGraph, chunk },
- { options, compilation }
- ) {
- const result = new ConcatSource(source);
- const exportsInfo = moduleGraph.getExportsInfo(module);
- const exports = [];
- const isAsync = moduleGraph.isAsync(module);
- if (isAsync) {
- result.add(
- `${RuntimeGlobals.exports} = await ${RuntimeGlobals.exports};\n`
- );
- }
- for (const exportInfo of exportsInfo.orderedExports) {
- if (!exportInfo.provided) continue;
- const varName = `${RuntimeGlobals.exports}${Template.toIdentifier(
- exportInfo.name
- )}`;
- result.add(
- `var ${varName} = ${RuntimeGlobals.exports}${propertyAccess([
- /** @type {string} */
- (exportInfo.getUsedName(exportInfo.name, chunk.runtime))
- ])};\n`
- );
- exports.push(`${varName} as ${exportInfo.name}`);
- }
- if (exports.length > 0) {
- result.add(`export { ${exports.join(", ")} };\n`);
- }
- return result;
- }
- }
- module.exports = ModuleLibraryPlugin;
|