Webpack“Resolve”功能是否解决了AMD风格的路径定义?

时间:2015-04-10 14:33:03

标签: javascript node.js amd webpack

我正在尝试在这里使用一个非常简单的概念证明...我有一个使用AMD的js lib,但是我需要将依赖关系解析为node_modules。所以我有以下内容:

webpack.config.js

module.exports = {
  entry: "./resources/content/scripts/twitter_module",
  output: {
    path: path.join(__dirname, "build"),
    filename: "out.js",
  },
  resolve: {
    root: __dirname,
    modulesDirectories: [ path.join(__dirname, "node_modules") ]
  }
};

这是我从webpack获得的输出:

Hash: bab530b56faec6755978
Version: webpack 1.8.2
Time: 49ms
 Asset    Size  Chunks             Chunk Names
out.js  8.6 kB       0  [emitted]  main
   [0] ./resources/content/scripts/twitter_module.js 6.44 kB {0} [built] [3 errors]

ERROR in ./resources/content/scripts/twitter_module.js
Module not found: Error: Cannot resolve module 'vendor.asset.jquery/jquery' in /Users/bob/projects/repository/resources/content/scripts
 @ ./resources/content/scripts/twitter_module.js 3:0-198:2

ERROR in ./resources/content/scripts/twitter_module.js
Module not found: Error: Cannot resolve module 'vendor.asset.jquery/jquery.ie.cors' in /Users/bob/projects/repository/resources/content/scripts
 @ ./resources/content/scripts/twitter_module.js 3:0-198:2

ERROR in ./resources/content/scripts/twitter_module.js
Module not found: Error: Cannot resolve module 'vendor.asset.moment/moment' in /Users/bob/projects/repository/resources/content/scripts
 @ ./resources/content/scripts/twitter_module.js 3:0-198:2

输出表明未使用/应用resolve配置。它仍在寻找导入它们的模块的同一目录中的脚本。解析只适用于common.js需要吗?我读过的文档和示例中的每一件事似乎都表明这应该有效。

包括目录结构:

➜  repository  pwd
/Users/bob/projects/repository

➜  repository  ls resources/content/scripts/twitter_module.js
resources/content/scripts/twitter_module.js

这些供应商包中存在外部依赖关系:

➜  repository  ls vendor.asset.jquery/content/scripts/jquery.js
vendor.asset.moment/content/scripts/jquery.js

➜  repository  ls vendor.asset.moment/content/scripts/moment.js
vendor.asset.moment/content/scripts/moment.js

1 个答案:

答案 0 :(得分:0)

所以我遇到的问题是Webpack日志输出似乎有点误导。当你有多个"解决"虽然搜索其他路径并在解析配置中定义了根路径,但似乎webpack仅将当前目录报告为缺少的依赖项的位置。如果您的根解析路径中存在路径问题,则webpack并不表示它试图查看那里。