Skip to content

PageLoad 处理模块

fybug edited this page Jan 20, 2020 · 1 revision

PageLoad 模块用于处理 html 页面

加载 html 页面并指页面的私有 js 模块、html 的加载配置、拓展配置等

编译时为单独页面单独配置,使用 HtmlWebpackPlugin

使用

方法参数较多,但是只有前面两个参数是必要的s

方法

addPage 加载页面

需传入参数

( 输出时的名称, 页面模版路径, [该页面的私有模块], [拓展属性], [加载配置] )

示例

confload.runOf('PageLoad', /** @param {global#PageLoad} pageLoad */(pageLoad) => {
    // 仅定义需要的文件
    pageLoad.addPage('index', SourcePath + 'index.html');
    // 定义私有模块
    pageLoad.addPage('index', SourcePath + 'index.html', ['index']);
    // 定义拓展配置
    pageLoad.addPage('main', SourcePath + 'main.html', ['main'], {title: 'main'});
    // 定义加载配置
    pageLoad.addPage('main', SourcePath + 'main.html', ['main'], {title: 'main'}, {outsuffix: '.php'});
});

拓展配置

拓展配置可用于 html 模版中定义的参数

即定义的拓展配置会加入到最后编译的 HTML 配置中

未加入

{
  meta: {
    "viewport": "width=device-width, initial-scale=1, shrink-to-fit=n",
    "x-ua-compatible": "ie=edge"
  }, cache: false
}

加入拓展配置

{
  title: "a"
}

输出为

{
  meta: {
    "viewport": "width=device-width, initial-scale=1, shrink-to-fit=n",
    "x-ua-compatible": "ie=edge"
  }, cache: false,
  title: "a" 
}

加载配置

加载配置为处理模块加载 html 页面时的配置

名称 说明 默认值
outsuffix 输出的文件后缀 .html
favicon 网页图标 IconPath
inject js 标签插入的位置 head
pubchuncks 是否导入全局模块 true