How to exclude files from Dojo's Build System?

白昼怎懂夜的黑 提交于 2019-12-06 09:52:13

问题


I'm following the official documentation page about the topic but I cannot configure it to ignore .txt files.

I have a all.profile.js on the root of my project:

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

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

And this is the package.json inside the folder myapp:

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

And this is the myapp.profile.js also inside the folder 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;
            }
        }
    };
})();

Finally, this is the folder structure:

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

The build tool runs fine, it reads and process all files but the .txt files are still on the release dir.

Please let me know if you spot any mistakes on my logic or how I'm configuring the build system. I'm using Dojo 1.9.1.

Thanks in advance.


回答1:


I'm not sure what is wrong with my initial scenario but here are the changes that I made to have the desired result:

  1. Move the trees declaration from the myapp.profile.js to all.profile.js inside the 'myapp' package definition.
  2. Instead of specifying the root of the trees, check everything and exclude accordingly: [".", ".", /(\/\.)|(~$)|(test|txt)/]

The final 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)/]
            ]
        }
    ]
};

If anyone can pin point exactly what I was doing wrong, please share.



来源:https://stackoverflow.com/questions/19409720/how-to-exclude-files-from-dojos-build-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!