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

grunt-spm-server

v0.2.7

Published

A Grunt task plugin, transport `CommonJS` module dynamically for `SeaJS` environment.

Downloads

46

Readme

grunt-spm-server

NPM version Build Status NPM downloads David David

A Grunt task plugin, transport CommonJS module dynamically for SeaJS environment.

Grunt 插件:通过 Web 服务实时地转换 CommonJS 模块以方便 SeaJS 环境中的开发调试。

背景

  • SPM 版本从 2 升级到 3,遵循的规范从 CMD 转为 CommonJS;
  • 前端开发调试过程中需要对 CommonJS 模块动态 Wrapping;
  • 纯前端的解决方案 seajs-wrap 存在不少弊端。

用法

$ npm install --save-dev grunt-spm-server
grunt.initConfig({
  server: {
    // 开发环境
    develop: {
      options: {
        // API mocking 文件存放目录
        api: './mock',
        // 指向上级目录
        base: '..',
        release: false
      }
    },
    // 仿真线上环境
    release: {
      options: {
        base: '..',
        release: true
      }
    }
  }
});
$ grunt server:develop
$ grunt server:release

参数

src

Type: `Array | String`
config 文件模板路径,可选。

dest

Type: `String`
config 文件存放路径,可选,默认 `'lib/config.js'`。

options.api

Type: `String`
API mocking 文件存放目录。
// json
{
  "/url/to/foo": {
    "POST": {
      "code": 0,
      "message": "POST ok",
      "notice_id": "xxxxxxx"
    },
    "PATCH": {
      "code": 0,
      "message": "PATCH ok",
      "notice_id": "xxxxxxx"
    }
  },
  "/url/to/bar": {
    // asterisk match any RESTful request method
    "*": {
      "code": 0,
      "message": "ok"
    }
  }
}

// or js
module.exports = {
  '/foo/bar': {
    // function is support
    'GET': function(url, query) {
      return {
        'MOCKAPI': {
          // means redirect
          'status': '302',
          'location': '/foo/bar' + query.match(/id=([^&]+)/)[1] + '.png'
        }
      };
    }
  }
};

options.base

Type: `String`
Default value: `'.'`
Web 服务根目录。

options.config

Type: `Boolean`
Default value: `true`
是否生成 config 文件。

options.port

Type: `Number`
Default value: `8851`
Web 服务侦听端口。

options.release

Type: `Boolean`
Default value: `true`
是否模拟线上环境,为 `true` 则不执行服务端 wrapping。

options.rule

Type: `Function | RegExp`
路径匹配函数,可选,返回 `true` 则执行服务端 wrapping。
function(url, query, idleading) {
  if (query.indexOf('nowrap') !== -1) {
    return false;
  }

  if (idleading) {
    if (idleading.indexOf('..') !== -1) {
      url = url.replace(/^\/[^\/]+/, '');
    } else if (url.indexOf('/' + idleading) !== -1) {
      url = url.substring(idleading.length + 1);
    }
  }

  // 默认匹配
  return /^\/(((app|mod|spm_modules|src).+)|index)\.(css|handlebars|json|js)$/.test(url);
}

// or RegExp
/^\/(((app|mod|spm_modules|src).+)|index)\.(css|handlebars|json|js)$/