12345678910111213141516171819202122232425262728293031323334353637383940 |
- 'use strict';
- const _ = require('lodash');
- module.exports = function (source) {
-
- const options = this.getOptions();
- const force = options.force || false;
- const allLoadersButThisOne = this.loaders.filter((loader) => loader.normal !== module.exports);
-
- if (allLoadersButThisOne.length > 0 && !force) {
- return source;
- }
-
- const htmlWebpackPluginLoaders = this.loaders.filter((loader) => loader.normal === module.exports);
- const lastHtmlWebpackPluginLoader = htmlWebpackPluginLoaders[htmlWebpackPluginLoaders.length - 1];
- if (this.loaders[this.loaderIndex] !== lastHtmlWebpackPluginLoader) {
- return source;
- }
-
- if (/\.(c|m)?js$/.test(this.resourcePath) && !force) {
- return source;
- }
-
-
- const template = _.template(source, { interpolate: /<%=([\s\S]+?)%>/g, variable: 'data', ...options });
-
-
- return 'var _ = eval("require")(' + JSON.stringify(require.resolve('lodash')) + ');' +
- 'module.exports = function (templateParams) { with(templateParams) {' +
-
- 'return (' + template.source + ')();' +
- '}}';
- };
|