1 |
|
2 |
|
3 | "use strict";
|
4 | const _template = require("lodash/template");
|
5 |
|
6 | module.exports = function (source) {
|
7 |
|
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 |
|
16 | if (allLoadersButThisOne.length > 0 && !force) {
|
17 | return source;
|
18 | }
|
19 |
|
20 |
|
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 |
|
31 | if (/\.(c|m)?js$/.test(this.resourcePath) && !force) {
|
32 | return source;
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 | const template = _template(source, {
|
38 | interpolate: /<%=([\s\S]+?)%>/g,
|
39 | variable: "data",
|
40 | ...options,
|
41 | });
|
42 |
|
43 |
|
44 | return (
|
45 | 'var _ = eval("require")(' +
|
46 | JSON.stringify(require.resolve("lodash")) +
|
47 | ");" +
|
48 | "module.exports = function (templateParams) { with(templateParams) {" +
|
49 |
|
50 | "return (" +
|
51 | template.source +
|
52 | ")();" +
|
53 | "}}"
|
54 | );
|
55 | };
|