1.0.7 • Published 12 months ago

rollup-plugin-ctf v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

插件参数配置

本插件的作用是关键词与你自己的js文件某方法做关联,在注释地方关键词会生成你映射的某方法去执行该方法代码
参数名类型说明
minitickPathstring输入你需要映射的方法所在的js文件的绝对地址或alias地址
injectMapobjectkey为你自定义的关键词,e.g. 埋点,value为你关键词映射的minitickPath在的js文件的方法名

例子

//需要映射的js文件 test.js,项目路径假设为/src/test.js
function a(){
    console.log("无参数")
}
function b(x){
    console.log("一个参数:::",x)
}
function c(x,y){
    console.log("两个个参数:::",x,y)
}
module.exports = {
    a:a,
    b:b,
    c:c
}

//vite.config.js
import ctfPlugin from "rollup-plugin-ctf";
...
export default defineConfig({
  plugins: [
    ctfPlugin({
        minitickPath:'/src/test.js',
        injectMap:{
            "我的":a,
            "你的":b
            "他的":c
        }
    })
  ]
})

【/src/index.js】
...
//不传参数注入
function test1(){
    //[我的]
    console.log("test1")
}
//传参数字符串注入
function test2(){
    //[你的]:一个参数
    console.log("test2")
}
function test3(){
    //[他的]:你-我
    console.log("test3")
}
//传参数变量注入
function test4(){
    let a = "变量1"
    //[你的]:$a
    console.log("test4")
}
function test5(){
    let a = "变量1";
    let b = {x:1,y:2};
    //[他的]:$a-$b
    console.log("test5")
}
function test6(){
    let a = "变量1";
    let d = "变量2";
    let c=true;
    //[你的]:$`${c?a:d}`
    console.log("test6")
}
...

编译后

// /src/index.js
function test1(){
    a();
    console.log("test1")
}
//传参数字符串注入
function test2(){
    b('一个参数');
    console.log("test2")
}
function test3(){
    c('你','我');
    console.log("test3")
}
//传参数变量注入
function test4(){
    let a = "变量1"
    b(a);
    console.log("test4")
}
function test5(){
    let a1 = "变量1";
    let b1 = {x:1,y:2};
    c(a1,b1);
    console.log("test5")
}
function test6(){
    let a = "变量1";
    let d = "变量2";
    let c=true;
    b(`${c?a:d}`)
    console.log("test6")
}

:注释的地方即为代码插入的地方

1.0.7

12 months ago

1.0.6

2 years ago

1.0.5

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago