-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathgetLibraryNamespace.js
More file actions
20 lines (17 loc) · 977 Bytes
/
getLibraryNamespace.js
File metadata and controls
20 lines (17 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* Gets the library namespace for React Refresh injection.
* @param {import('../types').NormalizedPluginOptions} pluginOptions Configuration options for this plugin.
* @param {import('webpack').Compilation["options"]["output"]} outputOptions Configuration options for Webpack output.
* @returns {string | undefined} The library namespace for React Refresh injection.
*/
function getLibraryNamespace(pluginOptions, outputOptions) {
if (pluginOptions.library) return pluginOptions.library;
if (outputOptions.uniqueName) return outputOptions.uniqueName;
if (!outputOptions.library || !outputOptions.library.name) return;
const libraryName = outputOptions.library.name;
if (Array.isArray(libraryName)) return libraryName[0];
if (typeof libraryName === 'string') return libraryName;
if (Array.isArray(libraryName.root)) return libraryName.root[0];
if (typeof libraryName.root === 'string') return libraryName.root;
}
module.exports = getLibraryNamespace;