MCPcopy Index your code
hub / github.com/webpack/webpack-dev-server / getStaticItem

Method getStaticItem

lib/Server.js:899–966  ·  view source on GitHub ↗
(optionsForStatic)

Source from the content-addressed store, hash-verified

897 * @returns {NormalizedStatic} normalized options for static
898 */
899 const getStaticItem = (optionsForStatic) => {
900 const getDefaultStaticOptions = () => ({
901 directory: path.join(process.cwd(), "public"),
902 staticOptions: {},
903 publicPath: ["/"],
904 serveIndex: { icons: true },
905 watch: getWatchOptions(),
906 });
907
908 /** @type {NormalizedStatic} */
909 let item;
910
911 if (typeof optionsForStatic === "undefined") {
912 item = getDefaultStaticOptions();
913 } else if (typeof optionsForStatic === "string") {
914 item = {
915 ...getDefaultStaticOptions(),
916 directory: optionsForStatic,
917 };
918 } else {
919 const def = getDefaultStaticOptions();
920
921 item = {
922 directory:
923 typeof optionsForStatic.directory !== "undefined"
924 ? optionsForStatic.directory
925 : def.directory,
926 staticOptions:
927 typeof optionsForStatic.staticOptions !== "undefined"
928 ? { ...def.staticOptions, ...optionsForStatic.staticOptions }
929 : def.staticOptions,
930 publicPath:
931 typeof optionsForStatic.publicPath !== "undefined"
932 ? Array.isArray(optionsForStatic.publicPath)
933 ? optionsForStatic.publicPath
934 : [optionsForStatic.publicPath]
935 : def.publicPath,
936 serveIndex:
937 // Check if 'serveIndex' property is defined in 'optionsForStatic'
938 // If 'serveIndex' is a boolean and true, use default 'serveIndex'
939 // If 'serveIndex' is an object, merge its properties with default 'serveIndex'
940 // If 'serveIndex' is neither a boolean true nor an object, use it as-is
941 // If 'serveIndex' is not defined in 'optionsForStatic', use default 'serveIndex'
942 typeof optionsForStatic.serveIndex !== "undefined"
943 ? typeof optionsForStatic.serveIndex === "boolean" &&
944 optionsForStatic.serveIndex
945 ? def.serveIndex
946 : typeof optionsForStatic.serveIndex === "object"
947 ? { ...def.serveIndex, ...optionsForStatic.serveIndex }
948 : optionsForStatic.serveIndex
949 : def.serveIndex,
950 watch:
951 typeof optionsForStatic.watch !== "undefined"
952 ? typeof optionsForStatic.watch === "boolean"
953 ? optionsForStatic.watch
954 ? def.watch
955 : false
956 : getWatchOptions(optionsForStatic.watch)

Callers

nothing calls this directly

Calls 1

isAbsoluteURLMethod · 0.80

Tested by

no test coverage detected