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

gulp-seed

v1.3.2

Published

天猫前端通用的构建插件

Downloads

21

Readme

gulp-seed

Test coverage Build Status Dependency Status devDependency Status NPM version node License npm download

gulp-seed基于gulp开发,是天猫前端通用的构建插件,它的主要功能是:

  • KMD模块依赖提取、编译
  • 代码检查(主要是文件编码检查与调试代码扫描)
  • 代码压缩

Install

一、安装gulp 命令行工具

$ npm install -g gulp #安装gulp cli

ps:unix环境可能需要sudo权限

二、在项目目录安装gulp 和 gulp-seed

$ npm install --save-dev gulp
$ npm install --save-dev gulp-seed

三、创建gulpfile.js

在项目根目录下创建gulpfile.js,编写构建脚本,例如:

var path = require('path');
var gulp = require('gulp');
var code = require('gulp-seed');
//引入包配置
var pkg = require('./package.json');

//注册css构建任务
gulp.task('css', function () {
  return gulp.src('src/**/*.css')
    .pipe(code.lint())       //css代码检查
    .pipe(code.minify())     //css代码压缩
    .pipe(gulp.dest('build/'))
});

//注册js构建任务
gulp.task('js', function () {
  return gulp.src('src/**/*.js')
    .pipe(code.lint())       //js代码检查
    .pipe(code.dep({
      name: pkg.name,
      path: 'http://g.tbcdn.cn/tm/' + pkg.name + '/' + pkg.version + '/',
      exports:["*"]
    }))
    .pipe(code.minify())     //js代码压缩
    .pipe(gulp.dest('build/'))
});

//注册一个默认任务
gulp.task('default', ['css', 'js']);

Usage

在项目根目录下执行

$ gulp

这样就完成了你的前端js和css文件的代码检查、依赖提取和代码压缩过程。

Configuration

code.dep

  • name {String} 包名
  • path {String} 包路径
  • replacePathInJSWithVar {String} 用来变量名来替换seed.js中的host,例如g_config.assetsServer
  • version {String} 包版本
  • group {String} KISSY combo分组,默认是tm
  • feDependencies {Object} 前端模块(femodule)依赖
  • useRequireAsync {Boolean} 是否生成异步依赖到requires_async,默认为false
  • kissyConfig {Object} KISSY.config配置项
  • ignore {Array} 依赖解析时忽略的模式,可选值有:KISSY14KISSY5CJS
  • useCache: {Boolean} 生成seed自动merge上一次seed生成的结果,默认为false
  • useMuiCache: {Boolean} 缓存feDependencies生成的seed,默认为false
  • concurent: {Number} 拉取mui seed文件并发数
  • timeInterval: {Number} 拉取mui seed批次间隙
  • wrapAMDWhenNoExports: {Boolean} 是否在无module.exports时包裹define,默认为true
  • exports: {Array} 要对外暴露的文件路径列表, 默认是["*"], 例如['src/index.js']
  • useFeDepSeedOnly: {Boolean} 只对配置了的依赖进行seed合并及增加依赖信息
  • useDemandDepSeed: {Boolean} 只生成按需使用的seed内容
  • ignoreRequires: {Array} 需要ignore的rquire,将不会出现在 module.requires 中

exports 文件

** 如果gulp watch 报错 请先关闭 gulp-cache,具体机制在考虑优化中 **

一个组件对外暴露的文件如果单独引用的价值才有暴露的意义

有时我们的代码会分拆成多个功能文件,但最终只需提供一个index文件对外使用

这时最合理的处理方式将index文件依赖的文件统一打包成一个文件(如xtemplate只需暴露runtime)

功能描述:

  1. 将exports的文件所依赖的本地仓库文件打包到exports的文件
  2. 去除已打包过的seed多余信息

例子

|- src
  |- fn1.js
  |- fn2.js
  |- util.js

fn1 require fn2,fn2 require util,此时我们只想暴露fn1,fn2

exports配置为["src/fn1.js","src/fn2.js"]

打包完成后对应的暴露的文件只有fn1.js,fn2.js

seed信息为(util已被合并到fn2.js,seed中不再有对应依赖):

{
    fn1:{
        requires:["fn2"]
    }
}

最佳实践:

  1. 如果对外暴露的两个文件a,b同时都依赖一个文件c,c就有单独存在的意义,建议也export
  2. 如果对外暴露的文件a,异步require一个文件b, b有单独存在的意义,建议也export

更多gulp使用手册请参考Gulp.js官方文档

Test

$ npm run build # build the source code with babel
$ npm run dev # build automatically when files change
$ npm run test # run unit tests

License

The MIT License (MIT)

Copyright (c) 2015 tmallfe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.