How to require raw static html file on webpack
15,870
Try to use html-loader
:
import TestTemplate from 'html!./test.html';
Author by
user3531149
Updated on July 26, 2022Comments
-
user3531149 almost 2 years
I have written a simple template
test.html
<div>raw text with content</div>
all I want to do is requiring the raw file, with no modifications
like
require('./test.html'); // should return "<div>raw text with content</div>"
I have tried loading the html using the extra-text-plugin, but it doesn't work
var ExtractTextPlugin = require('extract-text-webpack-plugin'); module.exports = { module: { loaders: [ { test: /\.html$/, loader: 'html' } ] }, plugins: [ new ExtractTextPlugin("[name].html") ] };
-
user3531149 almost 8 yearsWhy does it return "exports = template_content" instead of just the template content? how am I supposed to fetch the content
-
Ali Khosro about 5 yearsHe did not have TestTemplate in his file!!!! Why everyone is saying import template form file.html in all answeres. There is no export in html file.
-
Tofandel about 2 years@AliKhosro because it's using html-loader.... Which basically puts your html in an export