Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  115] [ 4]  / answers: 1 / hits: 16972  / 9 Years ago, wed, april 22, 2015, 12:00:00

I'd like the same functionality like RequireJS empty: http://requirejs.org/docs/optimization.html#empty



My use-case is that I include jquery-migrate in development, but I'd like to exclude this when built for production.



Using IgnorePlugin just makes it not included, and when requireing it in the code, it then throws an error (Uncaught Error: Cannot find module jquery-migrate).



What I'd like to happen is for it to just return undefined, or something of the like (like empty: in RequireJS). Id like to not touch the import in the code, just configuring it to return undefined.



EDIT: Using NormalModuleReplacementPlugin works, if I point the replacement to an empty file. But keeping an empty file around just for this seems unnecessary.


More From » webpack

 Answers
58

I use the null-loader for blanking out modules.
The noop-loader can be used for a less awkward if-else in the config.



Try:



rules: [{
test: /jquery-migrate/,
use: IS_DEV ? 'null-loader' : 'noop-loader'
}]

[#66961] Monday, April 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anitadevonm

Total Points: 730
Total Questions: 93
Total Answers: 74

Location: Estonia
Member since Wed, Jun 8, 2022
2 Years ago
;