Blame view

node_modules/html-webpack-plugin/lib/loader.js 1.29 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  /* This loader renders the template with underscore if no other loader was found */
  '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) {
      // Loader API changed from `loader.module` to `loader.normal` in Webpack 2.
      return (loader.module || loader.normal) !== module.exports;
    });
    // This loader shouldn't kick in if there is any other loader
    if (allLoadersButThisOne.length > 0) {
      return source;
    }
    // Skip .js files
    if (/\.js$/.test(this.resourcePath)) {
      return source;
    }
  
    // The following part renders the tempalte with lodash as aminimalistic loader
    //
    // Get templating options
    const options = this.query !== '' ? loaderUtils.parseQuery(this.query) : {};
    const template = _.template(source, _.defaults(options, { variable: 'data' }));
    // Require !!lodash - using !! will disable all loaders (e.g. babel)
    return 'var _ = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('lodash')) + ');' +
      'module.exports = function (templateParams) { with(templateParams) {' +
        // Execute the lodash template
        'return (' + template.source + ')();' +
      '}}';
  };