使用r.js直接优化bower_components

时间:2014-02-27 20:40:44

标签: javascript requirejs

我在使用r.js优化bower_components/目录中的模块时遇到了问题。

我的基本项目目录结构如下所示:

- bower_components/
- src/
  - activities/
  - client/

...并且r.js配置列出了以下详细信息:

({
  appDir: 'src',
  baseUrl: 'client',
  dir: 'out',
  modules: [
    { name: 'scripts/main' },
    /* (+ more) */
  ]
})

我想优化文件 bower_components/socket.io-client/dist/socket.io,在...之外 baseUrl。正如the "Common Pitfalls" section of the Optimizer guide中所建议的,我正在尝试 定义文件的路径:

 ({
   appDir: 'src',
   baseUrl: 'client',
   dir: 'out',
+  paths: {
+    'socket.io': '../../bower_components/socket.io-client/dist/socket.io'
+  },
   modules: [
     { name: 'scripts/main' },
     /* (+ more) */
+    { name: 'socket.io' }
   ]
 })

...但这会产生以下错误:

Running "requirejs:prod" (requirejs) task
{ [Error: Error: Module ID 'socket.io' has a source path that is same as output path: /home/mike/projects/cee/bower_components/socket.io-client/dist/socket.io.js. Stopping, config is malformed.
    at /home/mike/projects/cee/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:26000:39
]
  originalError: [Error: Module ID 'socket.io' has a source path that is same as output path: /home/mike/projects/cee/bower_components/socket.io-client/dist/socket.io.js. Stopping, config is malformed.] }

path配置间接似乎是这样的 优化器不会尝试在输出目录外创建文件。在 同时,这显然没有发生。难道我做错了什么?或者是 这不是r.js的能力吗?

0 个答案:

没有答案
相关问题