Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

34 wiersze
1.3 KiB

  1. /* This loader renders the template with underscore if no other loader was found */
  2. // @ts-nocheck
  3. 'use strict';
  4. const _ = require('lodash');
  5. const loaderUtils = require('loader-utils');
  6. module.exports = function (source) {
  7. // Get templating options
  8. const options = this.query !== '' ? loaderUtils.getOptions(this) : {};
  9. const force = options.force || false;
  10. const allLoadersButThisOne = this.loaders.filter(function (loader) {
  11. return loader.normal !== module.exports;
  12. });
  13. // This loader shouldn't kick in if there is any other loader (unless it's explicitly enforced)
  14. if (allLoadersButThisOne.length > 0 && !force) {
  15. return source;
  16. }
  17. // Skip .js files (unless it's explicitly enforced)
  18. if (/\.js$/.test(this.resourcePath) && !force) {
  19. return source;
  20. }
  21. // The following part renders the template with lodash as aminimalistic loader
  22. //
  23. const template = _.template(source, _.defaults(options, { interpolate: /<%=([\s\S]+?)%>/g, variable: 'data' }));
  24. // Require !!lodash - using !! will disable all loaders (e.g. babel)
  25. return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
  26. 'module.exports = function (templateParams) { with(templateParams) {' +
  27. // Execute the lodash template
  28. 'return (' + template.source + ')();' +
  29. '}}';
  30. };