【问题标题】:How to require raw static html file on webpack如何在 webpack 上要求原始静态 html 文件
【发布时间】:2016-12-05 20:02:59
【问题描述】:

我写了一个简单的模板

test.html

<div>raw text with content</div>

我想要做的只是需要原始文件,无需修改

喜欢

require('./test.html'); // should return "<div>raw text with content</div>"

我尝试使用额外文本插件加载 html,但它不起作用

var ExtractTextPlugin = require('extract-text-webpack-plugin'); 

module.exports =
{
    module:
    {
        loaders:
            [
                { test: /\.html$/, loader: 'html' }
            ]
    },
    plugins: [
        new ExtractTextPlugin("[name].html")
    ]
};

【问题讨论】:

  • 不要使用 Webpack 作为构建系统 - 不是。 Webpack 是一个用于 JS 和您在其中使用的静态资产的模块捆绑器。
  • 顺便说一句 - webpack 与 gulp/grunt 配合得非常好。

标签: javascript html node.js npm webpack


【解决方案1】:

尝试使用html-loader:

 import TestTemplate from 'html!./test.html';

【讨论】:

  • 为什么它返回“exports = template_content”而不仅仅是模板内容?我应该如何获取内容
  • 他的文件中没有TestTemplate!!!!为什么每个人都在所有答案中都说导入模板表单 file.html。 html文件中没有导出。
猜你喜欢
  • 2019-01-02
  • 2018-05-15
  • 2017-06-12
  • 2019-05-13
  • 2017-01-21
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2019-02-07
相关资源
最近更新 更多