Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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 网页包:在另一个部分中包含html部分?_Webpack_Partial_Html Webpack Plugin_Webpack Html Loader - Fatal编程技术网

Webpack 网页包:在另一个部分中包含html部分?

Webpack 网页包:在另一个部分中包含html部分?,webpack,partial,html-webpack-plugin,webpack-html-loader,Webpack,Partial,Html Webpack Plugin,Webpack Html Loader,有没有一种方法可以在另一个使用Web包的部分中包含html部分? 我正在使用html加载程序执行以下操作: index.html <%= require('html-loader!./partials/_header.html') %> <%= require('html-loader!./partials/_nav.html') %> <%= require('html-loader?root=.&minimize=true&interpola

有没有一种方法可以在另一个使用Web包的部分中包含html部分? 我正在使用html加载程序执行以下操作:

index.html

<%= require('html-loader!./partials/_header.html') %>
<%= require('html-loader!./partials/_nav.html') %>
<%= require('html-loader?root=.&minimize=true&interpolate!./partials/_header.html') %>
${require('html-loader?root=.!../partials/_nav.html')}

但是当我试图在_header.html中包含另一个部分时,它无法呈现它

这不起作用:

\u header.html

<%= require('html-loader!./partials/_header.html') %>
<%= require('html-loader!./partials/_nav.html') %>
<%= require('html-loader?root=.&minimize=true&interpolate!./partials/_header.html') %>
${require('html-loader?root=.!../partials/_nav.html')}

使用
html加载程序
插值
选项

{test://\(html)$/,
包括:path.join(uu dirname,'src/views'),
使用:{
加载器:“html加载器”,
选项:{
插值:真
}
}
}
然后在html页面中,您可以导入部分html和javascript变量


${require('./partials/top.html')}
家
${require('./partials/nav.html')}
${require('../js/html variables.js')。您好}
${require('./partials/footer.html')}
html variables.js
如下所示:

const hello='hello!';
const bye='bye!';
导出{你好,再见}
您还可以使用
${require('path/to/your/partial.html')
以同样的方式在另一个分部中包含分部


唯一的缺点是不能像这样从
HtmlWebpackPlugin
导入其他变量(至少我找不到导入它们的方法),只需在html中编写标题,或者在需要时使用单独的javascript文件来处理变量。

我结合了一些,找到了一个解决方案

index.html

<%= require('html-loader!./partials/_header.html') %>
<%= require('html-loader!./partials/_nav.html') %>
<%= require('html-loader?root=.&minimize=true&interpolate!./partials/_header.html') %>
${require('html-loader?root=.!../partials/_nav.html')}

你知道我不喜欢在多页应用程序中使用这种方法的地方:你必须重复你自己。在每个页面中,你必须要求顶部、导航和页脚。而不是只有一个包含它们的布局页面,你只需导入正文和该页面所需的所有其他内容。@Legends我不再使用html loader了,这里有很多解决这个问题的方法。例如,我做了这个(我也有一个更新的版本,当我有时间的时候我会上传它)