source: imaps-frontend/node_modules/html-webpack-plugin/lib/loader.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* This loader renders the template with underscore if no other loader was found */
2// @ts-nocheck
3"use strict";
4const _template = require("lodash/template");
5
6module.exports = function (source) {
7 // Get templating options
8 const options = this.getOptions();
9 const force = options.force || false;
10
11 const allLoadersButThisOne = this.loaders.filter(
12 (loader) => loader.normal !== module.exports,
13 );
14
15 // This loader shouldn't kick in if there is any other loader (unless it's explicitly enforced)
16 if (allLoadersButThisOne.length > 0 && !force) {
17 return source;
18 }
19
20 // Allow only one html-webpack-plugin loader to allow loader options in the webpack config
21 const htmlWebpackPluginLoaders = this.loaders.filter(
22 (loader) => loader.normal === module.exports,
23 );
24 const lastHtmlWebpackPluginLoader =
25 htmlWebpackPluginLoaders[htmlWebpackPluginLoaders.length - 1];
26 if (this.loaders[this.loaderIndex] !== lastHtmlWebpackPluginLoader) {
27 return source;
28 }
29
30 // Skip .js files (unless it's explicitly enforced)
31 if (/\.(c|m)?js$/.test(this.resourcePath) && !force) {
32 return source;
33 }
34
35 // The following part renders the template with lodash as a minimalistic loader
36 //
37 const template = _template(source, {
38 interpolate: /<%=([\s\S]+?)%>/g,
39 variable: "data",
40 ...options,
41 });
42 // Use `eval("require")("lodash")` to enforce using the native nodejs require
43 // during template execution
44 return (
45 'var _ = eval("require")(' +
46 JSON.stringify(require.resolve("lodash")) +
47 ");" +
48 "module.exports = function (templateParams) { with(templateParams) {" +
49 // Execute the lodash template
50 "return (" +
51 template.source +
52 ")();" +
53 "}}"
54 );
55};
Note: See TracBrowser for help on using the repository browser.