Giter Site home page Giter Site logo

grunt-cmd-transport's Introduction

grunt-cmd-transport

Transport javascript into cmd.

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-cmd-transport --save-dev

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

grunt.loadNpmTasks('grunt-cmd-transport');

The "transport" task

Overview

In your project's Gruntfile, add a section named cmd_transport to the data object passed into grunt.initConfig().

grunt.initConfig({
  transport: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

options.paths

Type: Array Default value: ['sea-modules']

Where are the modules in the sea.

options.idleading

Type: String Default value: ""

Prepend idleading to generate the id of the module.

options.alias

Type: Object Default value: {}

Alias of modules.

options.debug

Type: Boolean Default value: true

Create a debugfile or not.

options.handlebars

Type: Object

Options for handlebars compiler.

Configure handlebars ID:

options: {
    handlebars: {
        id: 'handlebars'
    }
}

options.uglify

Type: Object

Uglify prettifier, you really don't have to change this value.

options.parsers

Transport a specific filetype with the right parser.

You can write your own parsers, for example coffeeParser:

options: {
    parsers: {
        '.coffee': [coffeeParser]
    }
}

Sorry for the missing documentation on how to write a parser.

Usage Examples

Gruntfile use default options.

grunt.initConfig({
    transport: {
        target_name: {
            files: [{
                cwd: 'src',
                src: '**/*',
                dest: 'dist'
            }]
        }
    }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

Jan 23th, 2015 0.5.1

Fix css2js generate wrong code

Jan 22th, 2015 0.5.0

Support hash

Dec 4th, 2013 0.4.1

fix Windows path #58

Oct 15th, 2013 0.4.0

  • delete hack for grunt file object #45 not compatible

  • resolve deps error if require file and folder with the same name #50

Sep 4th, 2013 0.3.0

Remove styleBox id logic added in 0.2.12, now require outside css module do not adding to styleBox, that resolve lots of bugs.

Sep 4th, 2013 0.2.12

styleBox css module should has styleBox id.

Oct 28st, 2013 0.2.11

stylebox support array.

Oct 28st, 2013 0.2.10

stylebox support :root selector support id/deps sepecified don't resolve text!path/to/some.xx

Jul 1st, 2013 0.2.9

fix deps duplicate

Jun 27th, 2013 0.2.8

  • improve parsing css
  • add testcase

Jun 26th, 2013 0.2.7

  • improve log
  • remove .js extname in dependencies
  • add styleBox option

Jun 19th, 2013 0.2.6

Show parsing JS error log.

Jun 17th, 2013 0.2.5

Handlebars ID configurable.

Bugfix for not showing JS parse error.

May 28th, 2013 0.2.4

Use a specified version of Handlebars.

May 6th, 2013 `0.2.3

Don't stop the process when the file not exists.

April 25th, 2013 0.2.2

Fix on filter id.

April 15th, 2013 0.2.1

Restore tplParser.

April 11th, 2013 0.2.0

Changed the option configuration.

April 10th, 2013 0.1.3

Upgrade dependencies.

April 9th, 2013 0.1.2

Bugfix for parsing nested relative dependencies.

April 1st, 2013 0.1.1

Template process on source data.

April 1st, 2013 0.1.0

First version.

grunt-cmd-transport's People

Contributors

afc163 avatar edokeh avatar foxling avatar imyelo avatar lepture avatar lifesinger avatar popomore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-cmd-transport's Issues

关于构建有个小需求, 不知道能否实现

//开发版本
|---Gruntfile.js
|---seajs
|---project
   |----mod1
        |----js
            |---test.js
   |----mod2
//正是上线版本
|---seajs
|---project
        |------mod1
            |-----20130620
                |----js
                    |---test.js
        |------mod2

想通过构建工具来完成这步,

transport:{
    'project' : {
        options : {
            idleading: 'project/<%= pgk.version %>/',
            //通过package.json变量来生成id
            //如果这样做的话, id 路径不匹配, 会形成 id / src path 不知道该如何处理
            include : 'all
        },
        files : [
            {
                src : ['project/**/*], 
                dest : '.build/'
            }
        ]
    }
}
,
concat :{
    options : {
        include : 'all'
    },
    'project' : {
        files: [
            {
                expand: true,
                cwd: '.build/',
                src: ['**/*.js'],
                dest: '../dist/',
                ext: '.js'
            }
        ]
    }
}

我的想法
transport 通过 string/<%= pgk.version %>来生成id, 也就是一个文件夹能和模块匹配
concat 在合并时根据模块 id 或者 <%= pgk.versjon %> 来创建这些文件以及文件夹

搞了好久都没成, 如果能完成构建的话,能否给个实现方法, 感谢

貌似是只构建 mod1 -- js 的话 用 idleading 指定个id 应该可以
如果我想构建 全部项目, 也就是 project的话 就不会弄了
Gruntfile.js 和 project 在同一级上

windows 下提取出来的ID模块路径分隔符为"\\"

比如这样:

define("dist/test\\aaa", [ "./bbb" ], function(require, exports, module) {
    var bbb = require("./bbb");
    exports.tanchu = function() {
        alert(123123);
    };
});

define("dist/test\\bbb", [], function(require, exports, module) {
    var bbb = exports;
    bbb.alertmsg = function() {
        alert("This is message!");
    };
});

不知道是工具生成的问题还是配置有问题

Gruntfile.js文件

module.exports = function(grunt) {
  var transport = require('grunt-cmd-transport');

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    transport: {
        options : {
          idleading: 'dist/'
        },
        shareThing: {
            files : {
              '.build' : ['test/aaa.js', 'test/bbb.js']
            }
        }
    },
    concat: {
        shareThing: {
            files: {
                "sea-modules/dist/test/aaa.js": [".build/test/aaa.js", ".build/test/bbb.js"]
            }
        }
    },
    uglify : {
      shareThing : {
          files: {
            'sea-modules/dist/test/aaa.min.js': ['sea-modules/dist/test/aaa.js']
          }
      }
    },
    clean : {
        spm : ['.build']
    }
  });

  grunt.loadNpmTasks('grunt-cmd-transport');
  grunt.loadNpmTasks('grunt-cmd-concat');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');

  grunt.registerTask('build', ['transport', 'concat', 'uglify']);
};

Handlebars 模板一般是如何处理的?

使用 Underscore 内置的模板
比较简单,模板文件后缀定为 html ,在开发环境下启用 seajs text 插件即可
发布时,会将 html 文件转为 CMD 模块,合并进相应的其他模块,这样发布之后就可以去掉 text 插件了

使用 Handlebars 呢?
因为 Handlebars 模板允许预编译,所以麻烦一点,不知道你们的最佳实践是怎么样的?
我看到 transport 中默认对 handlebars 后缀的文件使用预编译处理,但是 text 插件只支持 tpl 和 html 后缀,这个是怎么做开发/发布环境的衔接的呢?
另外还看到了对 tpl 后缀的处理过程,貌似与 html 处理大同小异,不知道这是出于什么考虑提供的?

var isIE = !-[ 1 ];

var isIE = !-[1, ];通过grunt transport后变成var isIE = !-[ 1 ];
-v 0.2.0 and 0.2.8

使用require('seaBiz/jquery.lazyload.closure')(jQuery);这种方式写,没有被提取依赖

源码:
var $ = require('cQuery'),
jq = require('jQuery');
require('seaBiz/jquery.lazyload.closure')(jq);
var formCookieMod = require('seaBiz/formCookie').formCookieMod;
var searchPannel = require('seaBiz/searchPannel.js');

提取后的代码:
define(["cQuery","jQuery","seaBiz/formCookie","seaBiz/searchPannel.js"], function(){})

相比少了'seaBiz/jquery.lazyload.closure'

如何将html模板文件转为cmd模块

我的htm模板文件test.html如:

<div>test</div>
<div>second row</div>

,然后我的Gruntfile.js配置大概如下:

module.exports = function(grunt) {
    grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    transport: {
                options : {
                    paths : ['.'],
                    alias : '<%= pkg.spm.alias %>'
                },
                text : {
                    files : [{
                        expand :true,
                        cwd : 'src',
                        src : 'test.html',
                        dest : 'build/src'
                    }]
                }           
             }
    clean : {
        spm : ['.build']
    }
    });
    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-contrib-clean');

    grunt.registerTask('build', ['transport', 'clean']);
};

然后运行完grunt build之后转成的cmd模块就多了很多\n,而且文件名都变成了test.html.js,可是里面的模块id却还是test.html,结果如下:

define('src/test.html', [], '<div>test</div> \n<div>second row</div>');

请问要怎么配置才能去掉那些多余的\n呢?文件名不要变成*.html.js,因为本来是在seajs模块里面require这个模板文件回来的,请教,谢谢!

spm init 是 没找到 template

用 spm init 一个列子 为什么 提示找不到 template?求解答,在学习 spm 不太会用哇~~
D:\Documents\GitHub>spm init
Choosing "cmd" as defaute template.

Template "cmd" not exist.

Usage: spm-init [template]

Options:

-h, --help                output usage information
-V, --version             output the version number
-d, --debug               Enable debugging mode for tasks t
-v, --verbose             Show more infomation.
--stack                   Show stack message.
-i, --install <template>  Install template.
-u, --upgrade <template>  Update available template.
-l, --list                Show templates from index.
--update                  Get index from web.
-f, --force               Force to process the task.

Available templates:

No templates found

Change init directory in ~/.spm/spmrc

[init]
template = ~/.spm/init

关于设置 css 的 parsers问题

@lepture 。grunt-cmd-transport模块的gruntFile.js文件里,通过 var style = require('./').style.init(grunt); 获取style对象后,这样来设置 parsers -> parsers: { '.css': [style.cssParser, style.css2jsParser] }。但是,我在安装模块后,在模块外边没法获取style对象,所以没法通过style对象来设置parsers,请指教。

!text 前缀的模板,在 transport 时报错,说是 not found

Sea.js 在解析模块标识时, 除非在路径中有问号(?)或最后一个字符是井号(#),否则都会自动添加 JS 扩展名(.js)。

seajs-text: L20 https://github.com/seajs/seajs-text/blob/master/dist/seajs-text-debug.js#L20

globalEval('define("' + uri + '#", [], "' + jsEscape(content) + '")')

开发时,插件会给 id 自动加上井号,transport 应该是没做这处理。以前是好的,把 grunt-cmd-transport 升级后就这样了

cc @lifesinger

文件合并后相对路径发生变化

开发时希望文件结构清晰,js文件和css文件分开放,发布时文件能合并尽量合并。假如:
在开发时:js文件是放在"project/js/"路径下;css文件是放在"project/css/"路径下 ,这时在js文件里获取所需css文件就应该是 require("../css/css文件“)。但是在发布时,我把transport后的js和css模块合并,这时在js文件里获取所需css文件就应该是 require("./css文件“)。这会导致提取出来的依赖路径不对,这种情况有好的解决办法不。

transport/concat 不支持跨任务的父目录引入/合并模块

首先感谢 seajs/spmjs 团队给前端这个圈子带来极大的价值,我在构建项目时候,参照了这个用例:https://github.com/twinstony/seajs-grunt-build,我稍微改动下结构如下:

app                                 -- 特定项目特定页面的业务层js都在这里
    app1                            -- 其中的一个项目app1
        index                       
            src
                index.js         
    app2                            -- 更多 人/组 分别维护的 apps
    app3  
    app4  
    app5  
    app6  
    ...           

node_modules                        -- grunt
    grunt                           
    grunt-cmd-concat                
    grunt-cmd-transport             
    grunt-contrib-clean             
    grunt-contrib-uglify            
base
    libs                            -- 众多(工具)库
        seajs                               
            1.3.1                           
                seajs.js
        jquery
            x.x.0
                jquery.js
        mustache
        handlebars
        ...

    styles                          -- 几十个自定义模块
        component                       
            dialog
                src
                    dialog.js
                    dialog_css.css
            slide
            pagenav
            form
            ...                     


Gruntfile.js                        -- grunt配置文件
package.json                        -- 项目配置文件,该文件内容可以在grunt中引用
rootConfig.js                       -- 开发环境下使用的seajs配置文件

现在主要是两个问题:

  • base 比较庞大,源于模块更细粒度, grunt-build 任务时候,在往 .build 里同步文件会比较慢
  • apps 数量多,Gruntfile 会更加复杂,每个 app 对应最少一个任务,又由不同人维护,容易冲突

我期望的构建结构如下:

app                                 -- 特定项目特定页面的业务层js都在这里
    app1                            -- 其中的一个项目app1
        index                       
            src
                index.js         
        node_modules                -- app1 内部的 grunt
            grunt                           
            grunt-cmd-concat                
            grunt-cmd-transport             
            grunt-contrib-clean             
            grunt-contrib-uglify         
        Gruntfile.js                 -- app1 专属的 grunt 配置文件
        package.json                 -- 项目配置文件,该文件内容可以在grunt中引用
    app2                             
        index                       
            src
                index.js         
        node_modules                -- app2 内部的 grunt
            grunt                           
            grunt-cmd-concat                
            grunt-cmd-transport             
            grunt-contrib-clean             
            grunt-contrib-uglify         
        Gruntfile.js                 -- app2 专属的 grunt 配置文件
        package.json                 -- 项目配置文件,该文件内容可以在grunt中引用

    app3  
    app4  
    app5  
    app6  
    ...           

base
    libs                            -- 众多(工具)库
        seajs                               
            1.3.1                           
                seajs.js
        jquery
            x.x.0
                jquery.js
        mustache
        handlebars
        ...

    styles                          -- 几十个自定义模块
        component                       
            dialog
                src
                    dialog.js
                    dialog_css.css
            slide
            pagenav
            form
            ...                     

rootConfig.js                       -- 开发环境下使用的seajs配置文件

这样,每个 app 有各自的 构建策略,便于操作。事实上,在 transport 时候,对当前 app 下的 js 文件的依赖提取,包括部署到 .build 下都是 ok 的,只是没有同步 base 里被依赖的模块,当然也就没有被 concat 进去,这种构建结构是 grunt-cmd-concat/transport 所不支持的,打印了几行调试信息,貌似是在 transport 和 concat 的时候,会认为 .build 下有所有的文件,即便 base 里的也会去 .build 里查找,结果就是跨了 Gruntfile.js 的父目录,模块打包就失败。

我现在能想到的解决办法有:

  1. 把 base 里依赖的模块,给拷贝到当前的 app 下,按照 seajs-grunt-build 的用例方式打包,可以走通,这样为了 dirty+fast 的上线
  2. 依然在 根目录打包,但对 apps 开发不同的分支,master 分支无 Gruntfile.js ,即这个文件不被成员共享,各自独立维护,可以降低冲突,但仍然要操作整个 base 目录,依然耗时,准备打算用这种
  3. 等待 seajs-grunt-build 的 grunt-cmd-transport, grunt-cmd-concat 支持这种跨父目录引入模块的支持,在各个 app 内部进行 build

不知道哪里还可以改善,或者有更好的解决方式,在不改变现有目录结构的前提下?

如何打包非标准cmd组件

我想将非标准cmd组件,例如DD_belatedPNG封装为cmd组件

看了下examples,貌似没有例子

现在有没有基于Grunt的方案?

谢谢!

如何处理目录中非cmd的文件?

我目录中有非cmd的js文件,transport执行时,会有这样的问题:

 Cannot read property 'id' of undefined

找代码是 ast.js 中 parse函数返回了空数组造成的。

支持更多 seajs 模块定义方式

seajs 模块定义 id 和 deps 可以省略

define(id?, deps?, factory)

构建的时候需要兼容一下形式

define(id, factory)

id 不处理,仍然从 factory 分析 deps

define(id, deps, factory)

id 和 deps 都不处理,factory 中的 require 不会替换

define(deps, factory)

id 由构建生成,deps 不处理,factory 中的 require 不会替换

options.paths

@lepture
文档里写它的默认值是['sea-modules'],至今没有想明白这个有什么用,麻烦给举个应用场景说明它的用处,谢谢

使用pugin-shim后如何配置grunt-cmd-transport

我是这样写的,构建后运行报错了。shim插件没起作用

seajs.config({

    plugins: ['shim'],

    alias: {

        'backbone': {
            src: 'lib/backbone.js',
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
        }
     }

})

在grunt的transport task 中

grunt.initConfig({


      transport:{

            options:{

                   alias:{

                          backbone: 'lib/backbone.js'

                   }
            }
      }

});

[email protected] 版本有一个报错

qq20130930-2

从 Github 上安装的 grunt-cmd-transport,版本是 0.4.0,有如下报错:

qq20130930-3]

报错里的 src/cart 是一个子模块的目录。

从 NPM 安装的 grunt-cmd-transport 版本为 0.3.0 是 Ok 的,Grunt 配置完全一样。所以猜想可能是 0.4.0 版本有点问题。

transport:
  app:
    options:
      alias: grunt.file.readJSON "etc/spm_alias.json"
      debug: false
    files: [
      {
        expand: true
        cwd: "src"
        src: "**/*"
        dest: "dist/.build/"
      }
    ]
# END transport

构建后如果目录结构发生变化,grunt-cmd-transport的alias参数能否自动修改require()参数中的路径?

hi,我把所有的issue和官方文档都读了一遍,没有发现这个场景的答案,所以单独开一个新issue

在构建之前,代码是:
require("utils/src/utils"),加载src/utils/src/utils.js

构建之后,该文件放在sea-modules/planx/utils/1.0.0/utils下,所以require("utils/src/utils")就加载不到该js,需要写require("planx/utils/1.0.0/utils")

原来用spm build构建没有这个问题,因为我在package.json中有如下配置:
"alias":{
"utils/src/utils":"planx/utils/1.0.0/utils"
}
spm build的时候会自动把require()中的字符串替换掉

我在grunt-cmd-transport里也看到了alias配置项,我也配置成:
alias: { "utils/src/utils": "planx/utils/1.0.0/utils"},但是grunt transport时报错:

Warning: can't find module planx/utils/1.0.0/utils Use --force to continue.

因为我的源代码路径下并没有planx/utils/1.0.0/utils.js,构建后才会得到

请问这种场景要怎么处理?是有什么特殊的配置吗?还是必须保证源码和构建后的目录结构一致?谢谢

define的id问题

transport后,define的id为什么会有反斜杠,类似:define("lib\src\project",...
这科学?

option.parsers 的设置貌似覆盖了所有默认值

parsers: {
    '.handlebars': [handlebars_parser.parser]
}
...
files: [{
    cwd: 'src/',
    src: '**/*.js',
    dest: 'transport'
},{
    cwd: 'src/',
    src: 'templates/*.handlebars',
    dest: 'transport'
}]

这样设置之后只处理了handlebars,js没有被处理。
如果删掉parsers配置,js也可以被处理了。

如果require里面有占位符怎么办?

刚接触grunt,请多多包涵

define(function(require, exports, module) {
    var $= require('jquery');
    var lang = require('./i18n/{locale}') || {};
});

就如上面的,{locale} 这个是占位符,具体在seajs中来配置,但是我用grunt时,提示

D:\hello>grunt --force
Running "transport:webdesign" (transport) task
Transport src\background.ajax.js -> dist\background.ajax.js
>> can't find module jquery
found dependencies jquery
Transport src\background.js -> dist\background.js
>> can't find module jquery
Warning: Unable to read "src\i18n\{locale}.js" file (Error code: ENOENT). Used -
-force, continuing.

于是只编译出1个文件来,最后我只好建了一个叫 ’{local}.js‘的文件让他编译通过

顺便问下 如果懒得写path,不想jquery等的被转换,是不是就直接--force去编译就行了 不管警告?

谢谢!

transport是否支持遍历目录,提取出某个变量?

HI,翻了一遍issue,没有看到类似的帖子,所以新开一个issue,我的目录结构是这样的:

--webapps
    --employee
        --static
            abc.js
            def.js
            ......
    --pos
        --static
            123.js
            456.js
            ......

所以我的Gruntfile是这样的,对应每个子目录,创建一个transport target:

transport: {
            options: {
                paths: ['webapps'], // where is the module, default value is ['sea-modules']
                alias: aliasInfo
            },
            employee: {
                options: {
                    idleading: 'employee/static/'
                },
                files: [
                    {
                        cwd: 'webapps/employee/static',
                        src: '**/*.js',
                        dest: '.build/employee/static'
                    }
                ]
            },
            pos: {
                options: {
                    idleading: 'pos/static/'
                },
                files: [
                    {
                        cwd: 'applications/pos/static',
                        src: '**/*.js',
                        dest: '.build/pos/static'
                    }
                ]
            },

it works fine,问题是,跟employee和pos平行的这些子模块非常多,而它们的模式又都是一样的,只是模块名有区别。所以我想请问下,是否有办法插入一个自定义的函数,遍历webapps下的子目录,提取出类似{{module_name}}这样的变量,插入到idleading,cwd,dest等配置项里?

对获取file.src和file.dest的几点疑问

        // get the right filename and filepath
        if (fileObj.cwd) {
          // not expanded
          fname = fpath;
          fpath = path.join(fileObj.cwd, fpath);
        } else {
          fname = path.relative(fileObj.orig.cwd || '', fpath);
        }
        if (grunt.file.isDir(fpath)) {
          grunt.file.mkdir(fpath);
          return;
        }
        destfile = path.join(fileObj.orig.dest || fileObj.dest, fname);

直接用fileObj.src和fileObj.dest不就得了,grunt应该解析好了啊,为什么要自己解析,而且也没有考虑"ext"、“flatten”、"rename"这几个配置的处理?

/task/lib/script.js 的模块依赖输出的别名时有问题

//moduleDependencies方法当中,如果返回的是别名的话,对于后续的嵌套依赖关系检查会不一致的,所以需要转换为实际的id之后再处理

parsed.forEach(function(meta) {
  meta.dependencies.forEach(function(dep) {
   //modified by ginano@20130606 
    dep= iduri.parseAlias(options, dep);
    dep = iduri.absolute(alias, dep);
    if (!_.contains(deps, dep) && !_.contains(ids, dep) && !_.contains(ids, dep.replace(/\.js$/, ''))) {
      deps.push(dep);
    }
  });
});

dest路径异常

目录结构如下:

/app
    /js
        core.js
        common.js
        /page
            index.js

    /tools
        Gruntfile.js
        package.json

Gruntfile task如下

transport: {
    options: {
        paths: ['../js'],
        debug: false
    },
    all: {
        files: [
            {
                expand: true,
                cwd: '../js',
                src: ['*.js', '**/*.js', '!lib/**', '!config.js'],
                dest: 'build/transport/',
            }
        ]
    }
}

运行结果(build/transport目录):

core.js/core.js
common.js/common.js
page/index.js/page/index.js

也就是路径部分好像有重复

修改grunt-cmd-transport/tasks/transport.js文件,将

destfile = path.join(fileObj.dest, fname);

修改为

destfile = fileObj.dest; // path.join(fileObj.dest, fname);

就正常了。不知道是我的目录结构问题还是什么原因。

配置参数里的cwd参数是什么意思呢?

grunt.initConfig({
transport: {
target_name: {
files: [{
cwd: 'src',
src: '*/',
dest: 'dist'
}]
}
}
});
请问cwd参数是什么用的?我在readme.md里没有找到对这个配置项的说明

transport提取的依赖,concat后会造成无效的http请求

code:

define(function (require) {

var incrementor = require("../util/package").incrementor;

var calculator = require("../util/package").calculator;

alert(incrementor.increment(22));
alert(calculator.add(4, 5));

});

经过grunt-cmd-transport之后,得到的js是:

define("bootstrap/main-debug", [ "../util/package-debug", "../util/calculator-debug", "../util/incrementor-debug" ], function(require) {
var incrementor = require("../util/package-debug").incrementor;
var calculator = require("../util/package-debug").calculator;
alert(incrementor.increment(22));
alert(calculator.add(4, 5));
});

这里的问题是,除了需要的../util/package-debug以外,把更深层的依赖calculator-debug和incrementor-debug也写到了依赖数组里

然后我用grunt-cmd-concat,进行合并,最后只保留一个package.js,没有calculator和incrementor存在

但是在浏览器dev-console里看到,仍然对不存在的calculator和incrementor发起请求,并得到404响应。功能没有影响,但是发起了大量不必要的请求

我尝试手工删除了多余的依赖,改成:
define("bootstrap/main-debug", [ "../util/package-debug"], function(require) {
var incrementor = require("../util/package-debug").incrementor;
var calculator = require("../util/package-debug").calculator;
alert(incrementor.increment(22));
alert(calculator.add(4, 5));
});

就不会再发起无效请求了。请问这个是否是一个BUG,还是有文档里没有提到的配置项?谢谢

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.