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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Javascript 如何使用html加载器在webpack(版本2)中包含html部分?_Javascript_Webpack_Include_Require_Partials - Fatal编程技术网

Javascript 如何使用html加载器在webpack(版本2)中包含html部分?

Javascript 如何使用html加载器在webpack(版本2)中包含html部分?,javascript,webpack,include,require,partials,Javascript,Webpack,Include,Require,Partials,我正在努力通过html加载器将一个简单的footer.html作为一个html部分包含进来。我正在使用webpackversion 2 我尝试使用${require('**./footer.html**')}和${require('**../footer.html**')}失败 我没有使用ejs loader,也没有使用handlebar插件 是否有人知道我如何解决此问题,以及是否可以使用webpack呈现部分内容 谢谢你的建议 我使用html加载程序,只需添加 到我的mainindex.ht

我正在努力通过
html加载器
将一个简单的footer.html作为一个html部分包含进来。我正在使用
webpack
version 2

我尝试使用
${require('**./footer.html**')}
${require('**../footer.html**')}
失败

我没有使用ejs loader,也没有使用handlebar插件

是否有人知道我如何解决此问题,以及是否可以使用
webpack
呈现部分内容


谢谢你的建议

我使用
html加载程序
,只需添加

到我的main
index.html
。这对我来说很有用。

在Webpack.config文件中,您可以添加主html,如下所示

   plugins: [ 
    new HtmlWebpackPlugin({
        template: 'index.html'
    }),
    new ExtractTextPlugin('bundle.css')
],
在package.json中包含html加载程序,在config块中使用下面的方法就足够了

  $stateProvider.state('app', {
            url: '/app',
            template: require('html-loader!root/app/Common/templates/role.html'),
            controller: 'roleController'
        })

因此,所有部分都将捆绑在bundle.js本身中。无需在webpack config中添加加载程序,该功能被调用。在这里,
{test://\.html$/,use:['html-loader?interpolate']},
是一个网页配置规则,它通过指定
interpolate
标志来利用它。

我使用您的webpack.config.js文件进行了测试。您只需从中删除以下内容:

{
测试:/\.html$/,,
用法:['html-loader']
},

因此,.

您看到了什么样的失败?您预期会发生什么呢?它只是打印了${require('./footer.html')}标记,没有做任何操作。也许用html加载器无法呈现部分,不是吗?如果我使用标准加载器(可能是ejs),我会得到一个结果,但这会抛出一个文件类型错误?打印位置?@Mathias,您找到问题的解决方案了吗?不幸的是,它没有呈现要求状态。它只返回
你有“html加载程序”和“html网页包插件”吗?你也可以查看我的网页配置谢谢你的提示。我已经在webpack.config中安装了插件。我是否也必须在HtmlWebpackPlugin上创建分部?这是我的网页,非常感谢!这个解决方案现在很好用。现在可以用${require('./snippets/footer.html')}简单地加载部分了,这是一个很好的建议!如何仅为该部分文件包含css或SCS?