Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack DefinePlugin在html加载程序之后不立即运行_Webpack_Webpack Html Loader - Fatal编程技术网

Webpack DefinePlugin在html加载程序之后不立即运行

Webpack DefinePlugin在html加载程序之后不立即运行,webpack,webpack-html-loader,Webpack,Webpack Html Loader,我正在尝试将DefinePlugin与html加载程序一起使用。我在html加载程序中使用插值,并尝试在插值表达式中使用DefinePlugin中的值 当我加载到HtmlWebpackPlugin中,或者当html加载程序是html文件唯一使用的加载程序时,这项功能会起作用,但如果我从html加载程序加载到提取加载程序,则,DefinePlugin在extract loader尝试处理文件数据之前,似乎没有进行替换 例如: src/index.html: <!DOCTYPE html&g

我正在尝试将
DefinePlugin
html加载程序一起使用。我在
html加载程序中使用插值,并尝试在插值表达式中使用
DefinePlugin
中的值

当我加载到
HtmlWebpackPlugin
中,或者当
html加载程序
是html文件唯一使用的加载程序时,这项功能会起作用,但如果我从
html加载程序
加载到
提取加载程序
,则,
DefinePlugin
extract loader
尝试处理文件数据之前,似乎没有进行替换

例如:

src/index.html:

<!DOCTYPE html>
<html>
<head>
    <title>${ TITLE }</title>
</head>
<body>
</body>
</html>
这正如预期的那样工作,当观察输出
main.js
时,HTML的插入部分已替换为
title
My page title

当然,我想使用
extract loader
file loader
将这个HTML提取到一个单独的文件中。每次只执行这一步,我首先添加
extract loader
,以处理
html loader
的输出,如下所示:

...
    rules: [
      {
        test: /\.html$/,
        use: [
+++       "extract-loader",
          {
            loader: "html-loader",
            options: {
              interpolate: true
            }
          }
        ]
      }
    ]
...
这将导致生成失败:

ERROR in ./src/index.html
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) ReferenceError: TITLE is not defined

我的期望是,由于文件是由加载程序按顺序处理的,
TITLE
应该已经被
extractLoader.js
准备触摸它的时间所取代。我在这里遗漏了什么?

有同样的问题。订阅有同样的问题。订阅
ERROR in ./src/index.html
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) ReferenceError: TITLE is not defined