将html加载器添加到您的项目中:
npm i -D html-loader
将以下规则添加到webpack.config文件中:
{
test: /.(html)$/,
use: {
loader: ‘html-loader’,
options: {
attrs: [’:data-src’]
}
}
}
现在您可以按如下方式导入html文件:
import React, { Component } from ‘react’;
import Page from ‘./test.html’;
var htmlDoc = {__html: Page};
export default class Doc extends Component {
constructor(props){
super(props);
}
render(){
return (
)
}}
}}