Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript RequireJS-从优化构建中省略测试代码_Javascript_Unit Testing_Qunit_Requirejs - Fatal编程技术网

Javascript RequireJS-从优化构建中省略测试代码

Javascript RequireJS-从优化构建中省略测试代码,javascript,unit-testing,qunit,requirejs,Javascript,Unit Testing,Qunit,Requirejs,我一直在考虑基于RequireJS将测试集成到我的应用程序中。我发现了QUnit测试是如何集成到RequireJS结构中的。显然,您不希望测试代码在生产构建中随处可见在RequireJS中,如何在最终产品构建之外继续进行测试?在构建文件中可以设置许多选项。请参阅GitHub()上的完整示例 您要做的是从模块中排除某些项: //This module entry combines all the dependencies of foo/bar/bip into one file, //but

我一直在考虑基于RequireJS将测试集成到我的应用程序中。我发现了QUnit测试是如何集成到RequireJS结构中的。显然,您不希望测试代码在生产构建中随处可见在RequireJS中,如何在最终产品构建之外继续进行测试?

在构建文件中可以设置许多选项。请参阅GitHub()上的完整示例

您要做的是从模块中排除某些项:

 //This module entry combines all the dependencies of foo/bar/bip into one file,
 //but excludes foo/bar/bop and its dependencies from the built file. If you want
 //to exclude a module that is also another module being optimized, it is more
 //efficient if you define that module optimization entry before using it
 //in an exclude array.
    {
        name: "foo/bar/bip",
        exclude: [
            "foo/bar/bop"
        ]
    },

 //This module entry shows how to specify a specific module be excluded
 //from the built module file. excludeShallow means just exclude that
 //specific module, but if that module has nested dependencies that are
 //part of the built file, keep them in there. This is useful during
 //development when you want to have a fast bundled set of modules, but
 //just develop/debug one or two modules at a time.
    {
        name: "foo/bar/bin",
        excludeShallow: [
            "foo/bar/bot"
        ]
    }
您也可以使用正则表达式排除项,但这可能有些过分:

//When the optimizer copies files from the source location to the
//destination directory, it will skip directories and files that start
//with a ".". If you want to copy .directories or certain .files, for
//instance if you keep some packages in a .packages directory, or copy
//over .htaccess files, you can set this to null. If you want to change
//the exclusion rules, change it to a different regexp. If the regexp
//matches, it means the directory will be excluded. This used to be
//called dirExclusionRegExp before the 1.0.2 release.
//As of 1.0.3, this value can also be a string that is converted to a
//RegExp via new RegExp().

fileExclusionRegExp: /^\./,

如果您正在将CoffeeScript编译为JS,因此不需要编译目录中的
.coffee
文件,那么FileExclutionRegExp实际上非常有用。