1234567891011121314151617181920212223242526272829303132333435 |
- 'use strict';
- const _ = require('lodash');
- const loaderUtils = require('loader-utils');
- module.exports = function (source) {
- if (this.cacheable) {
- this.cacheable();
- }
- const allLoadersButThisOne = this.loaders.filter(function (loader) {
-
- return (loader.module || loader.normal) !== module.exports;
- });
-
- if (allLoadersButThisOne.length > 0) {
- return source;
- }
-
- if (/\.js$/.test(this.resourcePath)) {
- return source;
- }
-
-
-
- const options = this.query !== '' ? loaderUtils.parseQuery(this.query) : {};
- const template = _.template(source, _.defaults(options, { variable: 'data' }));
-
- return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
- 'module.exports = function (templateParams) { with(templateParams) {' +
-
- 'return (' + template.source + ')();' +
- '}}';
- };
|