我一直在研究基于 RequireJS 将测试集成到我的应用程序中。我发现了如何将 QUnit 测试集成到 RequireJS 结构中的这个示例。显然,您不希望测试代码存在于生产版本中。在 RequireJS 中,如何在最终的生产构建中保持测试?
问问题
953 次
1 回答
2
您可以在构建文件中设置很多选项。查看 GitHub 上的完整示例 ( https://github.com/jrburke/r.js/blob/master/build/example.build.js )
您要做的是从模块中排除某些项目:
//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: /^\./,
于 2012-03-29T17:04:32.170 回答