简体   繁体   English

如何使用 webpack 导入 HTML 文件?

[英]How can I import an HTML file using webpack?

I am trying to import an HTML file and use it as a template for a UI Element, but apparently I cannot configure webpack properly so it can read it.我正在尝试导入一个 HTML 文件并将其用作 UI 元素的模板,但显然我无法正确配置 webpack 以便它可以读取它。

For now I've got an error:现在我有一个错误:


Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently, no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|
|     <section id='hero'>
 @ ./src/js/components/landing/landing-component.js 5:0-59
 @ ./src/index.js

Webpack Configuration网络包配置

rules: [
            {
                test: /\.html$/i,
                loader: 'html-loader',
                options: {
                    minimize: true,
                    removeComments: true,
                }
            },
]

The way I am trying to import it我试图导入它的方式

import LandingTemplate from './landing-template.html'

我删除了我的 node_modules 和npm install安装了所有东西,它帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM