将加载器应用于特定文件

Cer*_*rad 3 javascript webpack

我正在关注http://alexomara.com/blog/webpack-and-jquery-include-only-the-parts-you-need使用webpack捆绑部分jQuery.

// webpack.config.js
module.exports = {
    entry: './entry',
    output: {
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            { 
                test: /jquery\/src\/selector\.js$/, 
                loader: 'amd-define-factory-patcher-loader' 
            }
        ]
    }
};
Run Code Online (Sandbox Code Playgroud)

事实证明,node_modules/jquery/src/selector.js由于AMD问题需要它自己的加载器.但是没有应用装载机.我在windows下运行,也许regexp需要调整?我试过不同的表情,但没有运气.

有关如何调试的任何建议?webpack新手.

正如所建议的,我补充说:

profile: true,
stats: {
  reasons: true,
  chunkModules: true,
  chunkOrigins: true,
  modules: true,
  cached: true,
  cachedAssets: true,
  source: true,
  errorDetails: true,
  publicPath: true,
  excludeModules: [
    /e\.js/
  ]
Run Code Online (Sandbox Code Playgroud)

运行webpack --display-modules收益率

Hash: 4a092c0d4d9e158a9bd7
Version: webpack 1.10.1
Time: 970ms
    Asset    Size  Chunks             Chunk Names
   bundle.js  876 kB       0  [emitted]  main
[0] ./entry.js 529 bytes {0} [built]
   factory:13ms building:12ms = 25ms
...
[14] ./~/jquery/src/traversing/var/rneedsContext.js 110 bytes {0} [built]
   [0] 25ms -> [11] 161ms -> [13] 473ms -> factory:196ms building:3ms dependencies:1ms = 859ms
[15] ./~/jquery/src/selector.js 33 bytes {0} [built]
   [0] 25ms -> [16] 172ms -> factory:449ms building:180ms = 826ms
[16] ./~/jquery/src/manipulation.js 15 kB {0} [built]
   [0] 25ms -> factory:16ms building:156ms dependencies:443ms = 640ms
...
Run Code Online (Sandbox Code Playgroud)

没有错误.没有任何实际价值.

Ale*_*ara 5

显然,Webpack没有规范化路径分隔符,因此我们必须更改正则表达式以适应Windows样式的目录分隔符.

这是一个可以使用的独立于平台的正则表达式,因此它可以在*nix系统和Windows上运行.

{ test: /jquery[\\\/]src[\\\/]selector\.js$/, loader: 'amd-define-factory-patcher-loader' }
Run Code Online (Sandbox Code Playgroud)

我还更新了博客文章以使用此表单.如果您仍有问题,请告诉我们!

完全披露:我写了这个问题所指的博客文章,并且碰巧今天发现了这个问题.