New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

test-build-plugin

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-build-plugin

code build test tool

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

test-build-plugin

代码打包检查工具,通过一些简单的配置,在打包的过程中检查,检查webpack的配置项是否正确,打包后的代码是否符合要求。

安装

npm install --save-dev test-build-plugin

使用

1)在项目的根目录中建立.testBuildConfig.js
2)在.testBuildConfig.js配置打包时的检查项

  • options:webpack 打包配置项,用来检查打包的入口和出口等配置正确;
  • codeRules.mustHave:用来配置必须有的代码,test: 检测的范围;val: 代码;
  • 用来配置必须禁止的代码,test: 检测的范围;val: 代码
const path = require('path')
const resolvePath = dir => path.join(__dirname, dir)
module.exports = {
  // webpack 打包配置项
  options: {
    entry: {
      app: ''
    },
    output: {
      path: resolvePath(''),
      publicPath: ''
    }
  },
  codeRules: {
    // 用来配置必须有的代码,test: 检测的范围;val: 代码
    mustHave: [{
      test: /index\.html$/,
      val: ['abcdefg']
    }],
    // 用来配置必须禁止的代码,test: 检测的范围;val: 代码
    mustForbidden: [{
      test: /\.(js|html)$/,
      val: ['beta-api.m.jd.com']
    }]
  }

}

3)项目中引用

const TestBuildPlugin = require('test-build-plugin')

config.plugins.push(
  new TestBuildPlugin()
)

4)在打包指令中添加testBuild=1,比如:

"scripts": node build/build.js --testBuild"
}

根据指令参数是否引入插件

if (process.argv && process.argv.indexOf('--testBuild') > -1) {
  config.plugins.push(new TestBuildPlugin())
}

Keywords

webpack

FAQs

Package last updated on 04 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts