html-webpack-check-source-plugin

1.2.0 • Public • Published

A plugin for html-webpack-plugin to check your state source

这是一个html-webpack-plugin的插件,可以在打包的时候检查资源是否符合参数要求

用法

  • 需要先使用html-webpack-plugin
  • 在html-webpack-plugin后面增加下面代码
    var  HtmlWebpackCheckSourcePlugin = require('html-webpack-check-source-plugin'); 
 
    //plugin
    new HtmlWebpackCheckSourcePlugin({
        emitWarning: false,
        checkFn(resourceLink) {
            if (resourceLink.indexOf("http://") > -1) {
                return '链接带有http://'
            };
            if (resourceLink.indexOf('/lib/ts_sdk/test/core.js') > -1) {
                return '使用测试版资源'
            }
        }
    })
 

选项

open[选配][默认:true]

  • false:关闭插件
  • true:打开插件

emitWarning[选配][默认:false]

  • false:抛出错误,中断打包进程
  • true:抛出警告

checkFn[必填]

校验规则函数

checkFn(link:string)=> <string | boolean>

  • 返回string时,抛出的错误并提示return的内容
  • 返回boolean时,抛出错误并提示默认信息

效果

输入

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
</head>
 
<body>
    this is the elememt;
    <img src="http://www.baidu.com" alt="">
    <img src="http://www.zhihu.com" alt="">
</body>
</html>
 

结果

更新

  • v1.0.0 完善api
  • v1.1.0 增加报错文件名提示
  • v1.2.0 增加api:open

Readme

Keywords

none

Package Sidebar

Install

npm i html-webpack-check-source-plugin

Weekly Downloads

2

Version

1.2.0

License

ISC

Unpacked Size

12.4 kB

Total Files

4

Last publish

Collaborators

  • wenqizuo