什么会导致webpack以递归方式包含每个文件?

时间:2017-01-05 16:20:01

标签: javascript webpack

我有一个基于AMD的项目。当我使用webpack构建它时,webpack开始加载模块,并最终由于某种原因递归地通过wildcard / glob加载。我试图阻止它。

例如webpack的输出

   [0] ./fixme.js 1.9 kB {0} [built]
   [1] ./host/CaptureContext.js 21.1 kB {1} [built] [1 error]
   [2] ./shared/Settings.js 1.2 kB {1} [built]
   [3] ./shared/Extensions.js 1.87 kB {1} [built]
   [4] ./shared/EventSource.js 1.61 kB {1} [built]
   [5] ./shared/Hacks.js 215 bytes {1} [built]
   [6] ./shared/Info.js 122 kB {1} [built]
   [7] ./shared/Utilities.js 8.47 kB {1} [built]
   [8] ./shared/Base.js 2.38 kB {1} [built]
   [9] ./host/Frame.js 16.1 kB {1} [built]
  [10] ./host/StateSnapshot.js 13.1 kB {1} [built]
  [11] ./host/Notifier.js 1.34 kB {1} [built]
  [12] ./host/ResourceCache.js 7.36 kB {1} [built] [1 error]
  [13] ./host/resources/Program.js 10.3 kB {1} [built]
  [14] ./host/Resource.js 5.43 kB {1} [built]
  [15] ./host/ResourceVersion.js 1.75 kB {1} [built]
  [16] ./host/resources/Buffer.js 11.7 kB {1} [built]
  [17] ./host/resources/Framebuffer.js 4.53 kB {1} [built]
  [18] ./host/resources/Renderbuffer.js 2.88 kB {1} [built]
  [19] ./host/resources/Shader.js 2.97 kB {1} [built]
  [20] ./host/resources/Texture.js 29.5 kB {1} [built]
  [21] ./shared/GLConsts.js 31.7 kB {1} [built]
  [22] ./host/resources/VertexArrayObject.js 9.38 kB {1} [built]
  [23] ./host/resources/VertexArrayObjectOES.js 2.12 kB {1} [built]
  [24] ./host/Statistics.js 4.16 kB {1} [built]
  [25] ./host/HostUI.js 10.1 kB {1} [built]
  [26] ./CSSLoader.js 2.33 kB {1} [built]
  [27] . ^\.\/.*$ 128 kB {1} [built] [761 warnings]
  [28] ./buildextensions.sh 0 bytes [optional] [built] [failed]
  [29] ./dependencies/require.js 86.6 kB {1} [optional] [built]
  [30] ./dependencies/reset-context.css 0 bytes [optional] [built] [failed]
  [31] ./dependencies/stacktrace.js 14.8 kB {1} [optional] [built]
  [32] ./dependencies/syntaxhighlighter_3.0.83/LGPL-LICENSE 0 bytes [optional] [built] [failed]
  [33] ./dependencies/syntaxhighlighter_3.0.83/MIT-LICENSE 0 bytes [optional] [built] [failed]
  [34] ./dependencies/syntaxhighlighter_3.0.83/shBrushGLSL.js 2.91 kB {1} [optional] [built] 

第27行

  [27] . ^\.\/.*$ 128 kB {1} [built] [761 warnings]

是什么原因造成的?我没有通过wildcard / glob加载模块的任何引用。只使用require.js和普通的AMD,程序在没有webpack的情况下工作正常。

./fixme.js看起来像这样

require([
     './host/CaptureContext',
     './host/HostUI',
     './CSSLoader',
  ], function(
      captureContext,
      HostUI,
      cssLoader) {
});

如果我在

中注释掉第2行
require([
     './host/CaptureContext',
//     './host/HostUI',
//     './CSSLoader',
  ], function(
      captureContext,
      HostUI,
      cssLoader) {
});

然后webpack只包含大约24个模块,并且不会试图以递归方式包含整个树。

当然,我会开始从模块中移除东西以试图缩小问题范围,但我的第一次尝试没有任何运气,所以我正在寻找想法是什么导致了这个

1 个答案:

答案 0 :(得分:0)

问题显然是其中一个文件中有这个。

var url = require.toUrl(filename);

Webpack看到了那条线,显然假设需要所有文件。注释掉线路修复是个问题。