如何从Dojo的Build System中排除文件?

时间:2013-10-16 17:20:00

标签: javascript dojo amd dojo-build

我正在关注official documentation page about the topic,但我无法将其配置为忽略.txt个文件。

我项目的根目录中有all.profile.js

var profile = (function(){
    return {
        basePath: "./",
        releaseDir: "../web",
        action: "release",
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        mini: true,
        stripConsole: "all",

        packages: [
            { name: "myapp", location: "myapp" }
        ]
    };
})();

这是文件夹package.json中的myapp

{
    "dojoBuild": "myapp.profile.js",
    "name": "my-app",
    "description": "This is My App",
    "version": "1.0",
    "main": "src"
}

这也是文件夹myapp.profile.js内的myapp

var profile = (function(){
    return {
        // don't need to do anything on the 'test' folder so don't define it on the trees.
        trees: [
            ["libs","libs",/txt$/], // ignore .txt files -> DOESN'T WORK!
            ["src","src",/txt$/]    // ignore .txt files -> DOESN'T WORK!
        ],
        resourceTags: {
            test: function(filename, mid){
                console.log("[test] filename: ",filename);
                return filename.indexOf("test/") !== -1;
            },
            copyOnly: function(filename, mid){
                //console.log("[copyOnly] mid: ",mid);
                return false;
            },
            miniExclude: function (filename, mid) {
                console.log("[miniExclude] filename: ",filename);
                return mid in {
                    'myapp/myapp.profile': 1,
                    'myapp/package.json': 2
                } || mid.indexOf(".txt") !== -1; // .txt are not ignored so exclude them...
            },
            amd: function(filename, mid) {
                //console.log("[amd] mid: ",mid);
                // myapp is not AMD but this will 'convert' it
                return false;
            }
        }
    };
})();

最后,这是文件夹结构:

web_dev/
-- myapp/
---- libs/
---- src/
---- test/
---- myapp.profile.js
---- package.json
-- all.profile.js

构建工具运行正常,它会读取并处理所有文件,但.txt文件仍在发布目录上。

如果您发现我的逻辑错误或我如何配置构建系统,请告诉我。我正在使用Dojo 1.9.1。

提前致谢。

1 个答案:

答案 0 :(得分:1)

我不确定我的初始场景有什么问题,但这是我为达到预期效果所做的更改:

  1. trees声明从myapp.profile.js移至 “myapp”包定义中的all.profile.js
  2. 不要指定树的根,请检查 所有内容并相应排除:[".", ".", /(\/\.)|(~$)|(test|txt)/]
  3. 最终all.profile.js

    var profile = {
        basePath: "./",
        releaseDir: "../web",
        releaseName: "built",
        action: "release",
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        mini: true,
        stripConsole: "all",
    
        packages: [
            {
                name: "myapp",
                location: "myapp",
                trees: [
                    // don't bother with .hidden, tests and txt.
                    [".", ".", /(\/\.)|(~$)|(test|txt)/]
                ]
            }
        ]
    };
    

    如果有人能确切指出我做错了什么,请分享。

相关问题