代码之家  ›  专栏  ›  技术社区  ›  Mathias

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

  •  3
  • Mathias  · 技术社区  · 7 年前

    html-loader .我正在使用 webpack

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

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

    有人知道如何解决这个问题,以及是否可以用 .

    谢谢你的建议!

    4 回复  |  直到 7 年前
        1
  •  3
  •   Serg Bolten    7 年前

    我使用 html-loader 只需添加 <%= require('html-loader!./partial/header.html') %> 到我的主要 index.html

        2
  •  1
  •   Felicio    7 年前

    该功能称为 interpolation 在这里 { test: /\.html$/, use: ['html-loader?interpolate'] }, 规则 interpolate 旗帜

        3
  •  0
  •   Raphael    7 年前

    在网页包中。配置文件,您可以像下面这样添加主html

       plugins: [ 
        new HtmlWebpackPlugin({
            template: 'index.html'
        }),
        new ExtractTextPlugin('bundle.css')
    ],
    

    在包中包含html加载程序。仅在配置块中使用以下方法就足够了。

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

        4
  •  0
  •   Sidharth Ravi    7 年前

    我测试了你的webpack.config。js文件。你要做的就是 以下内容:

    {
        test: /\.html$/,
        use: ['html-loader']
    },
    

    因此 fallback lodash loader comes into play .