Coder Social home page Coder Social logo

grunt-seajs-build's Introduction

grunt-seajs-build

构建Sea.js模块。包括:提取ID、依赖和合并文件。

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-seajs-build --save-dev

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

grunt.loadNpmTasks('grunt-seajs-build');

The "seajs_build" task

Overview

在项目的Gruntfile里面加入类似代码:

grunt.initConfig({
  "seajs_build" : {
    options : {   // seajs_build的选项
        outputPath    : "build"
      , seajsBasePath : "js"

      , path      : "."
      , scheme    : null
      , alias     : null
      , resolveID : null
      , recursive : true
      , buildType : "exclude_merge"
    }
    , your_target : { 
        options : { path : "." }
      , files : [{ 
            src        : "js/main.js"
          , dest       : "js/main.js"
          , filter     : "isFile"
          , concatDeps : true
      }]
    }
  }
})

Options

options.outputPath

类型 : String 默认值 : "build"

seajs_build的输出目录,相对于Gruntfile。

options.seajsBasePath

类型 : String 默认值 : "."

指向Sea.js的base路径,相对于Gruntfile。

options.path

类型 : String 默认值 : "."

指定要对哪个文件夹里面的文件进行处理。相对于seajsBasePath

options.scheme

类型 : String, Function 默认值 : null

当遇到require("XXX")时,如果在当前Task里面找到这个XXX文件,则利用scheme来生成这个文件的ID。
如果未定义scheme,则ID是XXX文件的路径。
如果scheme是字符串,则将会把scheme里面的{{filename}}替换成XXX文件的路径。
scheme可以是一个函数 : function(require){return id;},用于返回依赖的ID。

options.alias

类型 : Function 默认值 : null

和scheme类似,但只能是函数。当在当前Task里面找不到XXX文件的时候,会利用alias来生成这个文件的ID。
如果未定义,则ID是XXX文件的路径。

options.resolveID

类型 : Function 默认值 : null

在提取ID、依赖,并改写define()的时候,需要将已经获取的"依赖ID列表"转成"依赖路径列表"。
此时,可以利用resolveID : function( id ){ return path; } 来进行转换。
注意 : 在resolveID里面,如果id需要由task自己处理,应该返回undefined或者null
这个参数的使用场合可以参考complex例子

options.recursive

类型 : Bool 默认值 : true

如果为true, 提取ID、依赖的时候将会对path里面的子文件夹一并处理。

options.buildType

类型 : String 默认值 : "exclude_merge" 可选值 : "all", "merge_only", "exclude_merge"

生成方法。
all : 提取ID、依赖,并把结果输出到outputPath。然后再将合并文件输出到outputPath
merge_only : 提取ID、依赖,但只把合并文件输出到outputPath
exclude_merge : 提取ID、依赖,输出合并文件。然后把所有没有合并的文件输出到outputPath

target.files

类型 : Grunt Files

每一个target里面的files指定提取完ID、依赖之后,哪些文件需要合并在一起。

target.files.concatDeps

类型 : Bool 默认值 : false

Grunt files的额外参数。指定在合并的时候,是否把files的所有依赖都合并到目标文件里面。

使用场景

请参考examples里面的例子 :

mindless : 小型网站。所有JS合并成一个巨大的JS文件。
common : 常见的网站结构。
complex : 复杂的结构,大项目里面包含子项目。

grunt-seajs-build's People

Contributors

warwithinme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

grunt-seajs-build's Issues

关于插件任务执行顺序问题

楼主你好
我使用了你的插件打包seajs模块,同时使用了uglify压缩js,我发现你的插件会把uglify的替换掉,是不是哪一步没按顺序执行呢?

      grunt.registerTask('default', ["less:production",'sass:production','seajs_build',"uglify"]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.