将加载程序应用于特定文件
Apply loader to specific file
我正在关注 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'
}
]
}
};
事实证明,由于 AMD 问题,node_modules/jquery/src/selector.js
需要它自己的加载器。但是没有应用装载机。我在 windows 下 运行,也许正则表达式需要调整?我尝试了不同的表达方式,但没有成功。
关于如何调试有什么建议吗? 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/
]
运行 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
...
没有错误。没有任何实际价值。
不确定您是否自己找到了解决方案,但是根据原始文章的评论部分:
http://alexomara.com/blog/webpack-and-jquery-include-only-the-parts-you-need/
当 运行 on Windows 时出现正确的正则表达式是:
test: /jquery\src\selector\.js$/, loader: "amd-define-factory-patcher-loader"
希望对您有所帮助!
显然 Webpack 没有规范化路径分隔符,因此我们必须更改正则表达式以适应 Windows 风格的目录分隔符。
这是您可以使用的独立于平台的正则表达式,因此它可以在 *nix 系统和 Windows 上工作。
{ test: /jquery[\\/]src[\\/]selector\.js$/, loader: 'amd-define-factory-patcher-loader' }
我还更新了博客 post 以使用此表单。如果您仍然遇到问题,请告诉我!
完全披露:我写了这个问题所指的博客post,今天碰巧发现了这个问题。
我正在关注 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'
}
]
}
};
事实证明,由于 AMD 问题,node_modules/jquery/src/selector.js
需要它自己的加载器。但是没有应用装载机。我在 windows 下 运行,也许正则表达式需要调整?我尝试了不同的表达方式,但没有成功。
关于如何调试有什么建议吗? 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/
]
运行 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
...
没有错误。没有任何实际价值。
不确定您是否自己找到了解决方案,但是根据原始文章的评论部分:
http://alexomara.com/blog/webpack-and-jquery-include-only-the-parts-you-need/
当 运行 on Windows 时出现正确的正则表达式是:
test: /jquery\src\selector\.js$/, loader: "amd-define-factory-patcher-loader"
希望对您有所帮助!
显然 Webpack 没有规范化路径分隔符,因此我们必须更改正则表达式以适应 Windows 风格的目录分隔符。
这是您可以使用的独立于平台的正则表达式,因此它可以在 *nix 系统和 Windows 上工作。
{ test: /jquery[\\/]src[\\/]selector\.js$/, loader: 'amd-define-factory-patcher-loader' }
我还更新了博客 post 以使用此表单。如果您仍然遇到问题,请告诉我!
完全披露:我写了这个问题所指的博客post,今天碰巧发现了这个问题。