admin管理员组文章数量:1399499
I'm following to bundle parts of jQuery using webpack.
// webpack.config.js
module.exports = {
entry: './entry',
output: {
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /jquery\/src\/selector\.js$/,
loader: 'amd-define-factory-patcher-loader'
}
]
}
};
It turns out that node_modules/jquery/src/selector.js
needs it own loader due to an AMD issue. But the loader is not being applied. I'm running under windows and maybe the regexp needs to be adjusted? I tried different expressions but no luck.
Any suggestions on how to debug? New to webpack.
As suggested, I added:
profile: true,
stats: {
reasons: true,
chunkModules: true,
chunkOrigins: true,
modules: true,
cached: true,
cachedAssets: true,
source: true,
errorDetails: true,
publicPath: true,
excludeModules: [
/e\.js/
]
Running webpack --display-modules
yields
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
...
No errors. Nothing of any real value.
I'm following http://alexomara./blog/webpack-and-jquery-include-only-the-parts-you-need to bundle parts of jQuery using webpack.
// webpack.config.js
module.exports = {
entry: './entry',
output: {
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /jquery\/src\/selector\.js$/,
loader: 'amd-define-factory-patcher-loader'
}
]
}
};
It turns out that node_modules/jquery/src/selector.js
needs it own loader due to an AMD issue. But the loader is not being applied. I'm running under windows and maybe the regexp needs to be adjusted? I tried different expressions but no luck.
Any suggestions on how to debug? New to webpack.
As suggested, I added:
profile: true,
stats: {
reasons: true,
chunkModules: true,
chunkOrigins: true,
modules: true,
cached: true,
cachedAssets: true,
source: true,
errorDetails: true,
publicPath: true,
excludeModules: [
/e\.js/
]
Running webpack --display-modules
yields
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
...
No errors. Nothing of any real value.
Share Improve this question edited Dec 19, 2016 at 16:04 Alexander O'Mara 60.7k19 gold badges173 silver badges181 bronze badges asked Jul 21, 2015 at 12:29 CeradCerad 48.9k9 gold badges92 silver badges94 bronze badges 4-
Have you turned on all of the diagnostic messages in
config.stats
? That way you can see if the loader is being hit or not. – Esteban Felix Commented Jul 21, 2015 at 18:16 - First time I have heard the term config.stats. Are you talking about the profile option? In any event, I'm fairly certain it's never being called. In fact, I can put in a bogus name and still get no errors. – Cerad Commented Jul 21, 2015 at 18:44
- It's not well documented but here is an example webpack stats config. Can you show an example of the outputted code for that module? – Esteban Felix Commented Jul 21, 2015 at 20:34
- Wow. A drive by down vote on a three year old question. Some people just have way too much time on their hands. – Cerad Commented Jul 19, 2018 at 14:21
2 Answers
Reset to default 5Apparently Webpack does not normalize the path separators, so we must alter the regex to acmodate Windows-style directory separators.
Here is a platform-independent regex you can use, so it can work on both *nix systems and Windows.
{ test: /jquery[\\\/]src[\\\/]selector\.js$/, loader: 'amd-define-factory-patcher-loader' }
I've also updated the blog post to use this form. If you continue to have trouble, let me know!
Full disclosure: I wrote the blog post to which this question is referring, and happened to discover this question about it today.
Not sure if you ever found the solution to this yourself however based on the ments section for the origional article:
http://alexomara./blog/webpack-and-jquery-include-only-the-parts-you-need/
It appears the correct regex when running on Windows is:
test: /jquery\\src\\selector\.js$/, loader: "amd-define-factory-patcher-loader"
Hope that helps!
本文标签: javascriptApply loader to specific fileStack Overflow
版权声明:本文标题:javascript - Apply loader to specific file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744218555a2595753.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论