Skip to content

searchfe/makit-plugin

Repository files navigation

makit-plugin

Language Build Status Coveralls npm package npm downloads semantic-release

makit-plugin

Install

npm i makit-plugin --save-dev

Get Start

makit-plugin 为基于 makit 的构建项目提供plugin的recipe封装,适用于中大型项目构建;同时提供部分必要的plugin(暂时性)。

RecipeFactory && recipeImpl

参数传递 可以通过RecipeFactory向recipeImpl传递一些参数,避免在repice中耦合业务代码

const comp = process.env.compress;

const recipe = RecipeFactory(recipeImpl, {key: '$1'});

rule(`(**/*).min.js`, `/$1.js`, RecipeFactory(recipeImpl, {
    comp,
}));

function recipeImpl({target, dep, comp}) {}

反向引用 可以在recipeImpl的options中的字符串参数中引用rule匹配到的字符串($0~$9)

const recipe = RecipeFactory(recipeImpl, {key: '$1'});

rule(`(**/*).min.js`, `/$1.js`, recipe);

function recipeImpl({target, dep, key}) {
    // target   frame.min.js
    // dep      frame.js
    // key      frame
}

配置 RecipeFactory可以接受一个配置集合,当recipeImpl执行前,符合target的配置会被选中,将传给recipeImpl。这样,recipe可以实现一些文件粒度的差异化配置

const configs = [{
    file: 'static/**.js',
    compress: true
}, {
    file: 'static/**.min.js',
    compress: false
}];

const recipe = RecipeFactory(recipeImpl, {key: '$1', ...dynamicOption}, configs);

rule(`(**/*).js`, `${src}/$1.js`, recipe);

recipe

compress

css

hash

inline-js

map

parse-js

san

tpl

wrap

deploy

utils

async-replace

entry

API

API DOC