🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

grunt-spm-server

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-spm-server

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

latest
Source
npmnpm
Version
0.2.7
Version published
Weekly downloads
2.3K
9726.09%
Maintainers
1
Weekly downloads
 
Created
Source

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)$/

Keywords

gruntplugin

FAQs

Package last updated on 27 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts