test-build-plugin

1.0.3 • Public • Published

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())
}

Package Sidebar

Install

npm i test-build-plugin

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

6.47 kB

Total Files

3

Last publish

Collaborators

  • king_queen