import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [];
function _createMdxContent(props) {
  const _components = Object.assign({
    p: "p",
    code: "code",
    pre: "pre",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsxs(_components.p, {
      children: ["大多数打包器（如 Webpack、Rollup、Parcel、Vite）在使用动态导入时会自动进行代码分割处理。Solid 的 ", jsx(_components.code, {
        children: "lazy"
      }), " 方法允许包装组件的动态导入来实现延迟加载。然后输出一个可以在 JSX 模板中正常使用的组件，它会在第一次渲染时在内部动态加载底层导入的代码，此时会暂停渲染分支直到代码可用。"]
    }), "\n", jsxs(_components.p, {
      children: ["使用 ", jsx(_components.code, {
        children: "lazy"
      }), " 替换 import 语句。"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "import"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Greeting"
        }), " ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "from"
        }), " ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"./greeting\""
        }), ";\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "用下面的代码替换："
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Greeting"
        }), " = ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "lazy"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "import"
        }), "(", jsx(_components.span, {
          className: "hljs-string",
          children: "\"./greeting\""
        }), "));\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "但是仍然可能因为加载太快而无法看到效果。但是如果想让加载更明显，你可以添加一个模拟延迟。"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Greeting"
        }), " = ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "lazy"
        }), "(", jsx(_components.span, {
          className: "hljs-keyword",
          children: "async"
        }), " () => {\n  ", jsx(_components.span, {
          className: "hljs-comment",
          children: "// 模拟延迟"
        }), "\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "await"
        }), " ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "new"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Promise"
        }), "(", jsxs(_components.span, {
          className: "hljs-function",
          children: ["(", jsx(_components.span, {
            className: "hljs-params",
            children: "r"
          }), ") =>"]
        }), " ", jsx(_components.span, {
          className: "hljs-built_in",
          children: "setTimeout"
        }), "(r, ", jsx(_components.span, {
          className: "hljs-number",
          children: "1000"
        }), "));\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "return"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "import"
        }), "(", jsx(_components.span, {
          className: "hljs-string",
          children: "\"./greeting\""
        }), ");\n});\n"]
      })
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=lesson-d53d6a38.js.map
