From de98e0b232509d5f40c135d540a70e415272ff85 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 May 2017 15:35:00 +0200 Subject: node_modules --- node_modules/html-webpack-plugin/lib/loader.js | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 node_modules/html-webpack-plugin/lib/loader.js (limited to 'node_modules/html-webpack-plugin/lib/loader.js') diff --git a/node_modules/html-webpack-plugin/lib/loader.js b/node_modules/html-webpack-plugin/lib/loader.js new file mode 100644 index 000000000..e1af5e513 --- /dev/null +++ b/node_modules/html-webpack-plugin/lib/loader.js @@ -0,0 +1,51 @@ +/* This loader renders the template with underscore if no other loader was found */ +'use strict'; + +var _ = require('lodash'); +var loaderUtils = require('loader-utils'); + +module.exports = function (source) { + if (this.cacheable) { + this.cacheable(); + } + var 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.request)) { + return source; + } + + // The following part renders the tempalte with lodash as aminimalistic loader + // + // Get templating options + var options = loaderUtils.parseQuery(this.query); + // Webpack 2 does not allow with() statements, which lodash templates use to unwrap + // the parameters passed to the compiled template inside the scope. We therefore + // need to unwrap them ourselves here. This is essentially what lodash does internally + // To tell lodash it should not use with we set a variable + var template = _.template(source, _.defaults(options, { variable: 'data' })); + // All templateVariables which should be available + // @see HtmlWebpackPlugin.prototype.executeTemplate + var templateVariables = [ + 'compilation', + 'webpack', + 'webpackConfig', + 'htmlWebpackPlugin' + ]; + return 'var _ = require(' + loaderUtils.stringifyRequest(this, require.resolve('lodash')) + ');' + + 'module.exports = function (templateParams) {' + + // Declare the template variables in the outer scope of the + // lodash template to unwrap them + templateVariables.map(function (variableName) { + return 'var ' + variableName + ' = templateParams.' + variableName; + }).join(';') + ';' + + // Execute the lodash template + 'return (' + template.source + ')();' + + '}'; +}; -- cgit v1.2.3