-----------------------------------------------------------------------
r.js 配置文件 example.build.js 不完整注释
-----------------------------------------------------------------------

  1. /*
  2. * This is an example build file that demonstrates how to use the build system for
  3. * require.js.
  4. *
  5. *
  6. * r.js 配置文件 example.build.js 不完整注释\
  7. * 结合最近打包实践,对这个 r.js 下的 build 配置文件作了些补充说明:
  8. *
  9. *
  10. * THIS BUILD FILE WILL NOT WORK. It is referencing paths that probably
  11. * do not exist on your machine. Just use it as a guide.
  12. *
  13. *
  14. */
  15.  
  16. ({
  17. // app顶级目录,非必选项。如果指定值,baseUrl则会以此为相对路径
  18. appDir: "some/path/",
  19.  
  20. // 模块根目录。默认情况下所有模块资源都相对此目录。
  21. // 若该值未指定,模块则相对build文件所在目录。
  22. // 若appDir值已指定,模块根目录baseUrl则相对appDir。
  23. baseUrl: "./",
  24.  
  25. // 配置文件目录
  26. mainConfigFile: '../some/path/to/main.js',
  27.  
  28. // 设置模块别名
  29. // RequireJS 2.0 中可以配置数组,顺序映射,当前面模块资源未成功加载时可顺序加载后续资源
  30. paths: {
  31. "foo.bar": "../scripts/foo/bar",
  32. "baz": "../another/path/baz"
  33. },
  34.  
  35. // 配置 CommonJS 的 package See http://requirejs.org/docs/api.html#packages for more information.
  36. packagePaths: [],
  37. packages: [],
  38.  
  39. // 指定输出目录,若值未指定,则相对 build 文件所在目录
  40. dir: "../some/path",
  41.  
  42. // 在 RequireJS 2.0.2 中,输出目录的所有资源会在 build 前被删除
  43. // 值为 true 时 rebuild 更快,但某些特殊情景下可能会出现无法预料的异常
  44. keepBuildDir: true,
  45.  
  46. // 国际化配置
  47. locale: "en-us",
  48.  
  49. // JS 文件优化方式,目前支持以下几种:
  50. // uglify: (默认) 使用 UglifyJS 来压缩代码
  51. // closure: 使用 Google's Closure Compiler 的简单优化模式
  52. // closure.keepLines: 使用 closure,但保持换行
  53. // none: 不压缩代码
  54. optimize: "uglify",
  55.  
  56. // 使用 UglifyJS 时的可配置参数
  57. // See https://github.com/mishoo/UglifyJS for the possible values.
  58. uglify: {
  59. toplevel: true,
  60. ascii_only: true,
  61. beautify: true,
  62. max_line_length: 1000
  63. },
  64.  
  65. // 使用 Closure Compiler 时的可配置参数
  66. closure: {
  67. CompilerOptions: {},
  68. CompilationLevel: 'SIMPLE_OPTIMIZATIONS',
  69. loggingLevel: 'WARNING'
  70. },
  71.  
  72. // CSS 优化方式,目前支持以下几种:
  73. // none: 不压缩,仅合并
  74. // standard: 标准压缩,移除注释、换行,以及可能导致 IE 解析出错的代码
  75. // standard.keepLines: 除标准压缩外,保留换行
  76. // standard.keepComments: 除标准压缩外,保留注释 (r.js 1.0.8+)
  77. // standard.keepComments.keepLines: 除标准压缩外,保留注释和换行 (r.js 1.0.8+)
  78. optimizeCss: "standard.keepLines",
  79.  
  80. // 是否忽略 CSS 资源文件中的 @import 指令
  81. cssImportIgnore: null,
  82.  
  83. // 一般用于命令行,可将多个 CSS 资源文件打包成单个 CSS 文件
  84. cssIn: "path/to/main.css",
  85. out: "path/to/css-optimized.css",
  86.  
  87. // 处理所有的文本资源依赖项,从而避免为加载资源而产生的大量单独xhr请求
  88. inlineText: true,
  89.  
  90. // 是否开启严格模式
  91. // 由于很多浏览器不支持 ES5 的严格模式,故此配置默认值为 false
  92. useStrict: false,
  93.  
  94. //Specify build pragmas. If the source files contain comments like so:
  95. //>>excludeStart("fooExclude", pragmas.fooExclude);
  96. //>>excludeEnd("fooExclude");
  97. //Then the comments that start with //>> are the build pragmas.
  98. //excludeStart/excludeEnd and includeStart/includeEnd work, and the
  99. //the pragmas value to the includeStart or excludeStart lines
  100. //is evaluated to see if the code between the Start and End pragma
  101. //lines should be included or excluded. If you have a choice to use
  102. //"has" code or pragmas, use "has" code instead. Pragmas are harder
  103. //to read, but they can be a bit more flexible on code removal vs.
  104. //has-based code, which must follow JavaScript language rules.
  105. //Pragmas also remove code in non-minified source, where has branch
  106. //trimming is only done if the code is minified via UglifyJS or
  107. //Closure Compiler.
  108. pragmas: {
  109. fooExclude: true
  110. },
  111.  
  112. //Same as "pragmas", but only applied once during the file save phase
  113. //of an optimization. "pragmas" are applied both during the dependency
  114. //mapping and file saving phases on an optimization. Some pragmas
  115. //should not be processed during the dependency mapping phase of an
  116. //operation, such as the pragma in the CoffeeScript loader plugin,
  117. //which wants the CoffeeScript compiler during the dependency mapping
  118. //phase, but once files are saved as plain JavaScript, the CoffeeScript
  119. //compiler is no longer needed. In that case, pragmasOnSave would be used
  120. //to exclude the compiler code during the save phase.
  121. pragmasOnSave: {
  122. //Just an example
  123. excludeCoffeeScript: true
  124. },
  125.  
  126. //Allows trimming of code branches that use has.js-based feature detection:
  127. //https://github.com/phiggins42/has.js
  128. //The code branch trimming only happens if minification with UglifyJS or
  129. //Closure Compiler is done. For more information, see:
  130. //http://requirejs.org/docs/optimization.html#hasjs
  131. has: {
  132. 'function-bind': true,
  133. 'string-trim': false
  134. },
  135.  
  136. //Similar to pragmasOnSave, but for has tests -- only applied during the
  137. //file save phase of optimization, where "has" is applied to both
  138. //dependency mapping and file save phases.
  139. hasOnSave: {
  140. 'function-bind': true,
  141. 'string-trim': false
  142. },
  143.  
  144. // 命名空间,完整实例可以参考 http://requirejs.org/docs/faq-advanced.html#rename
  145. namespace: 'foo',
  146.  
  147. // 跳过 pragmas 处理
  148. skipPragmas: false,
  149.  
  150. //If skipModuleInsertion is false, then files that do not use define()
  151. //to define modules will get a define() placeholder inserted for them.
  152. //Also, require.pause/resume calls will be inserted.
  153. //Set it to true to avoid this. This is useful if you are building code that
  154. //does not use require() in the built project or in the JS files, but you
  155. //still want to use the optimization tool from RequireJS to concatenate modules
  156. //together.
  157. skipModuleInsertion: false,
  158.  
  159. //Specify modules to stub out in the optimized file. The optimizer will
  160. //use the source version of these modules for dependency tracing and for
  161. //plugin use, but when writing the text into an optimized layer, these
  162. //modules will get the following text instead:
  163. //If the module is used as a plugin:
  164. // define({load: function(id){throw new Error("Dynamic load not allowed: " + id);}});
  165. //If just a plain module:
  166. // define({});
  167. //This is useful particularly for plugins that inline all their resources
  168. //and use the default module resolution behavior (do *not* implement the
  169. //normalize() method). In those cases, an AMD loader just needs to know
  170. //that the module has a definition. These small stubs can be used instead of
  171. //including the full source for a plugin.
  172. stubModules: ['text', 'bar'],
  173.  
  174. //If it is not a one file optimization, scan through all .js files in the
  175. //output directory for any plugin resource dependencies, and if the plugin
  176. //supports optimizing them as separate files, optimize them. Can be a
  177. //slower optimization. Only use if there are some plugins that use things
  178. //like XMLHttpRequest that do not work across domains, but the built code
  179. //will be placed on another domain.
  180. optimizeAllPluginResources: false,
  181.  
  182. // 处理级联依赖,默认为 false,此时能够在运行时动态 require 级联的模块。为 true 时,级联模块会被一同打包
  183. findNestedDependencies: false,
  184.  
  185. //If set to true, any files that were combined into a build layer will be
  186. //removed from the output folder.
  187. removeCombined: false,
  188.  
  189. modules: [
  190. {
  191. // 模块 alias 名称
  192. name: "foo/bar/bop",
  193.  
  194. //For build profiles that contain more than one modules entry,
  195. //allow overrides for the properties that set for the whole build,
  196. //for example a different set of pragmas for this module.
  197. //The override's value is an object that can
  198. //contain any of the other build options in this file.
  199. //
  200. override: {
  201. pragmas: {
  202. fooExclude: true
  203. }
  204. }
  205. },
  206.  
  207. // 将 alias 别名为 foo/bar/bop 和 foo/bar/bee 的模块打包成一个文件
  208. {
  209. name: "foo/bar/bop",
  210. include: ["foo/bar/bee"]
  211. },
  212.  
  213. // 将 foo/bar/bip 及其依赖项一并打包,但不包括 foo/bar/bop
  214. {
  215. name: "foo/bar/bip",
  216. exclude: [
  217. "foo/bar/bop"
  218. ]
  219. },
  220.  
  221. // 排除指定模块,但若该模块对所打包文件有级联依赖关系,则仍会被打包进去
  222. {
  223. name: "foo/bar/bin",
  224. excludeShallow: [
  225. "foo/bar/bot"
  226. ]
  227. },
  228.  
  229. // insertRequire 在 RequireJS 2.0 中被引入,在 built 文件的末尾插入 require([]) 以触发模块加载并运行
  230. // insertRequire: ["foo/baz"] 即 require(["foo/baz"])
  231. // 详情见 https://github.com/jrburke/almond
  232. {
  233. name: "foo/baz",
  234. insertRequire: ["foo/baz"]
  235. }
  236. ],
  237.  
  238. // 仅优化单个模块及其依赖项
  239. name: "foo/bar/bop",
  240. include: ["foo/bar/bee"],
  241. insertRequire: ['foo/bar/bop'],
  242. out: "path/to/optimized-file.js",
  243.  
  244. // An alternative to "include"
  245. deps: ["foo/bar/bee"],
  246.  
  247. // RequireJS 2.0 中,out 可以是一个函数
  248. out: function (text) {
  249. // 自定义优化内容
  250. },
  251.  
  252. // 模块包裹函数,顾名思义使用特定内容包裹模块,如此一来 define/require 就不再是全局变量,在 end 中可以暴露一些全局变量供整个函数使用
  253. wrap: {
  254. start: "(function() {",
  255. end: "}());"
  256. },
  257.  
  258. // 另一种模块包裹方式
  259. // (function() { + content + }());
  260. wrap: true,
  261.  
  262. // 另一种模块包裹方式,包裹内容可以是指定文件
  263. wrap: {
  264. startFile: "part/start.frag",
  265. endFile: "parts/end.frag"
  266. },
  267.  
  268. // 不优化某些文件
  269. fileExclusionRegExp: /^\./,
  270.  
  271. // 默认保留模块的 license 注释
  272. preserveLicenseComments: true,
  273.  
  274. // 设置 logging level
  275. // TRACE: 0,
  276. // INFO: 1,
  277. // WARN: 2,
  278. // ERROR: 3,
  279. // SILENT: 4
  280. // Default is 0.
  281. logLevel: 0,
  282.  
  283. // 在每个文件模块被读取时的操作函数,可在函数体内作适当变换
  284. onBuildRead: function (moduleName, path, contents) {
  285. return contents.replace(/foo/g, 'bar');
  286. },
  287.  
  288. // 在每个文件模块被写入时的操作函数
  289. onBuildWrite: function (moduleName, path, contents) {
  290. return contents.replace(/bar/g, 'foo');
  291. },
  292.  
  293. // 若为true,优化器会强制在文件中包裹一层 define(require, exports, module) {})
  294. cjsTranslate: true,
  295.  
  296. //Introduced in 2.0.2: a bit experimental.
  297. //Each script in the build layer will be turned into
  298. //a JavaScript string with a //@ sourceURL comment, and then wrapped in an
  299. //eval call. This allows some browsers to see each evaled script as a
  300. //separate script in the script debugger even though they are all combined
  301. //in the same file. Some important limitations:
  302. //1) Do not use in IE if conditional comments are turned on, it will cause
  303. //errors:
  304. //http://en.wikipedia.org/wiki/Conditional_comment#Conditional_comments_in_JScript
  305. //2) It is only useful in optimize: 'none' scenarios. The goal is to allow
  306. //easier built layer debugging, which goes against minification desires.
  307. useSourceUrl: true
  308. })

-----------------------------------------------------------------------
原文:http://nomospace.com/posts/r.js-example.build.js.html
-----------------------------------------------------------------------

r.js 配置文件 build.js 不完整注释的更多相关文章

  1. r.js的build.js的详细配置解析

    { baseUrl: "../src",//当前文件的父目录的兄弟src目录,意思是这个目录会被完全复制到dir目录下面 mainConfigFile: '../src/init- ...

  2. Vue中ESlint配置文件eslintrc.js文件详解

    最近在跟着视频敲项目时,代码提示出现很多奇奇怪怪的错误提示,百度了一下是eslintrc.js文件没有配置相关命令,ESlint的语法检测真的令人抓狂,现在总结一下这些命令的解释,方便以后查阅. 默认 ...

  3. webpack4打包报错ERROR in multi ./src/main.js dist/bundle.js

    webpack打包测试: 上边将mode01.js模块及main.js主文件编写完成,下边使用webpack对这些js文件进行打包 1.进入程序目录,执行webpack main.js build.j ...

  4. r.js 配置文件 example.build.js 不完整注释

    /* * This is an example build file that demonstrates how to use the build system for * require.js. * ...

  5. r.js build.js配置

    /* * This is an example build file that demonstrates how to use the build system for * require.js. * ...

  6. r.js合并实践 --项目中用到require.js做生产时模块开发 r.js build.js配置详解

    本文所用源代码已上传,需要的朋友自行下载:点我下载 第一步: 全局安装  npm install -g requirejs 第二步: 1.以下例子主要实现功能, 1)引用jq库获取dom中元素文本, ...

  7. vue-cli 2.x脚手架build目录中的webpack.base.conf.js配置文件

    此文章用来解释vue-cli脚手架build目录中的webpack.base.conf.js配置文件,适用于vue-cli 2.x版本 此配置文件是vue开发环境的wepack相关配置文件,主要用来处 ...

  8. vue-cli脚手架build目录中的build.js配置文件

    该随笔收藏自: vue-cli脚手架build目录中的build.js配置文件 这个配置文件是命令npm run build 的入口配置文件,主要用于生产环境 由于这是一个系统的配置文件,将涉及很多的 ...

  9. vue-cli脚手架build目录中的karma.conf.js配置文件

    本文系统讲解vue-cli脚手架build目录中的karma.conf.js配置文件 这个配置文件是命令 npm run unit 的入口配置文件,主要用于单元测试 这条命令的内容如下 "c ...

随机推荐

  1. java中的多线程——进度2

    package src;/*多线程总结:1,进程和线程的概念.    |--进程:    |--线程:2,jvm中的多线程体现.    |--主线程,垃圾回收线程,自定义线程.以及他们运行的代码的位置 ...

  2. Android Studio API 文档_下载与使用

    如何下载API 说明: 时间: 2016/7/9 根据百度经验步骤改编(百度经验), 但是比它更好, 亲测可用 1.1 下载API文档: 1.1.1 SDK Manager 1.1.2 1.1.3 ( ...

  3. Python 的格式化字符串format函数

    阅读mattkang在csdn中的博客<飘逸的python - 增强的格式化字符串format函数>所做笔记 自从python2.6开始,新增了一种格式化字符串的函数str.format( ...

  4. python使用psutil获取服务器信息

    >>> import psutil 获取cpu信息>>> psutil.cpu_times()scputimes(user=128258.38, nice=12.2 ...

  5. poj 2342 Anniversary party 树形DP入门

    题目链接:http://poj.org/problem?id=2342 题意:一家公司有1 <= N <= 6 000个职工,现要组织一些职工参加晚会,要求每个职工和其顶头上司不能同时参加 ...

  6. Git权威指南 读笔(4)

    第12章 改变历史: $ git commit --amend -m "Remove hello.h, which is useless." 修改提交说明 $ git log -- ...

  7. JAVA自学之-----FileInputStream类

    1, FileInputStream类函数创建: package coreJava; import java.io.FileInputStream; import java.io.IOExceptio ...

  8. jquery ashx

    http://www.cnblogs.com/wzcheng/archive/2010/05/20/1739810.html http://www.cnblogs.com/yyl8781697/arc ...

  9. POJ 3264 Balanced Lineup(RMQ)

    点我看题目 题意 :N头奶牛,Q次询问,然后给你每一头奶牛的身高,每一次询问都给你两个数,x y,代表着从x位置上的奶牛到y位置上的奶牛身高最高的和最矮的相差多少. 思路 : 刚好符合RMQ的那个求区 ...

  10. HDU2167+状态压缩DP

    状态压缩dp 详见代码 /* 状态压缩dp dp[ i ][ j ]:第i行j状态的最大和 dp[i][j] = max( dp[i-1][k]+sum[i][j] ); 题意:给定一个N*N的方格, ...