npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wepy-plugin-mockdata

v1.0.1

Published

WePY MockServer模拟数据配置合并插件

Downloads

7

Readme

wepy-plugin-mockdata

WePY MockServer模拟数据配置合并插件。实现在开发环境分JSON文件配置MockServer模拟数据。

安装

npm install wepy-plugin-mockdata --save-dev

使用

wepy.config.json 配置文件中配置:

  plugins: {
    'mockdata': {
      filter: new RegExp('mock.+index\\.js$')	    }
  }
  

配置

{
    src: 'src', //源文件目录,默认:'src'
    dist: 'dist', //目标文件目录,默认:'dist'
    filter: new RegExp('\w$'), //文件过滤,建议严格控制,以提升插件效率
    rule: new RegExp('export\\sdefault\\s([a-zA-Z0-9_]+)'), //规则匹配,不建议修改
    sourceMap: true, //是否开启sourceMap
    empty: false, // 是否清空,比如不是开发环境的时候,清空mock data的配置
    babelPlugins: [ // bale插件依赖和wepy.config.js中的 compilers.babel.plugins一致
        'transform-class-properties',
        'transform-decorators-legacy',
        'transform-object-rest-spread',
        'transform-export-extensions',
    ]
}

原理

  • 扫描指定目录下所有JSON配置文件,创建一个map
  • 将JSON配置merge到模块导出文件中,组装在一个总的配置文件

实例

文件结构

├── mock
│   ├── index.js
│   └── mock_api
│       ├── login.json
│       └── user
│           └── getUserInfo.json

插件处理结果

├── mock
│   └── index.js

插件处理前index.js的内容

let mockData = {
  'test.do': {status: 9000}
};
export default mockData;

插件处理后index.js的内容

var mockData = {
  'test.do': { status: 9000 }
};
mockData = Object.assign(mockData, { "mock_api/login": { "status": 0, "data": {} }, "mock_api/user/getUserInfo": { "userName": "jsonzhou" } });
exports.default = mockData;

清空配置

一般mock data配置只用于本地开发环境,在其它测试或生产环境,需要剔除掉这部份配置,防止增加小程序应用包的大小。

{
	"empty": true
}

如上配置,给插件设置empty===true,就会清空mock data的配置。上文中的index.js内容就会被清空。

var mockData = {};
exports.default = {};