javascript - Apply loader to specific file - Stack Overflow

I'm followingto bundle parts of jQuery using webpack. webpack.config.jsmodule.exports = {entr

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
Add a ment  | 

2 Answers 2

Reset to default 5

Apparently 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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744218556a4563669.html

相关推荐

  • javascript - Apply loader to specific file - Stack Overflow

    I'm followingto bundle parts of jQuery using webpack. webpack.config.jsmodule.exports = {entr

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信