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-commonizor

v0.1.1

Published

plugin for building js file to support commonjs

Downloads

29

Readme

@ali/grunt-commonizor

plugin for building js file to support commonjs

最新版本

0.3.9

Getting Started

安装本插件:

tnpm install @ali/grunt-commonizor --save-dev

如果没有安装tnpm请参考这里.

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-commonizor');

The "commonizor" task

Overview

本grunt插件根据配置将对应文件(比如env.js)输出为.common.js文件(比如env.common.js),输出后的文件可以通过commonJS规范的require方法引入。配合tnpm publish命令打包发布到tnpm上:

tnpm publish

发布到tnpm以后可以直接通过以下方式引用该组件了:

var env = require('@ali/lib-env');

Options

  • namespace: 发布到哪个名字空间(可选,值可以是'@ali'/'@alife'等,默认为'@ali')
  • name: 组件名字(可选,请按照组件命名规范命名,默认从package.json的name字段解析)
  • type: 组件类型(可选,值可以是lib/ctrl,默认从package.json的name字段解析)
  • pkg: 组件的package.json对象(可选,默认为根目录下的package.json)

使用方法

在gruntfile.js的initConfig配置参数中加入以下配置:

// 方式一:合并多个文件到一个common.js文件
commonizor: {
	js: {
	  options: {
      namespace: '@alife'
	  },
	  files: {
      '<%=distPath%>/helloamfe.common.js': [
          '<%=distPath%>/helloamfe.js',
          '<%=distPath%>/helloamfe_css.js'
        ]
	  }
  }
}

// 方式二:每个文件生成单独的common.js文件
commonizor: {
  js: {
    files: [{
      expand: true,
      cwd: '<%=distPath%>',
      src: ['a.js', 'b.js'],
      dest: '<%=distPath%>',
      ext: '.common.js'
    }]
  }
}

注意:0.3.0之前版本升级到当前版本后,gruntfile配置方式需要改为上面的方式

然后执行commonizor任务:

grunt.loadNpmTasks('@ali/grunt-commonizor');

grunt.registerTask('common', ['commonizor']);

在命令行里运行下面的命令即可打包出xxx.common.js文件。该文件支持commonjs依赖加载标准。 请注意如果写入权限不够需要在命令前面加上sudo,这样才有权限把依赖写入到package.json的dependencies字段

sudo grunt common

Release History

0.3.10

  • 修复对type-foo-bar命名规范的支持

0.3.9

  • 修复module.exports组件类型不正确的问题

0.3.7

  • 兼容不包含app/ctrl/lib的组件名

0.3.5

  • bugfix: 兼容名字中带有-或者.的组件名

0.3.2

  • bugfix: 多文件时module.exports只对主文件输出(其他文件通过global方式挂接)

0.3.1

  • 修正combo某些字段不应列入依赖的bug

0.3.0

  • 多个文件打包成一个commonjs文件
  • 支持ctrl组件的_css.js文件打包

0.2.15

  • bugfix: dependencies包版本兼容

0.2.12

  • 支持多文件、多任务

0.2.10

  • 打包.common.js文件
  • 依赖写入package.json文件
  • 自动把main、publishConfig写入package.json文件
  • 自动替换package.json的name为@ali/xx-xx的形式