admin管理员组文章数量:1594978
在通过html-webpack-plugin
解析html文件的时候,出现了“You may need an appropriate loader to handle this file type.”问题。
意思是我需要添加一些loader来解析html,网上基本上的解决方案是用babel
或者html-loader
。
babel
我嫌麻烦放弃了;html-loader
会和html-webpack-plugin
有冲突,导致html中的类似<%= htmlWebpackPlugin.options.title %>
的变量不能够正确解析了。
最后,我决定还是回归本源问题,最好减少引入的插件。
首先,我们参考一下官方文档:
这里的描述可以看出,template
属性是默认使用ejs
文件的。
什么是EJS呢?大家可以参考官网描述。
于是,我将index.html
更改为index.ejs
,配置的地方和文件都需要修改。
配置:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: './index.ts',
......,
plugins: [
new HtmlWebpackPlugin({
title: 'typescript examination',
template: './index.ejs',
chunks: ['app']
}),
]
}
重新运行一下,问题已经解决了。
本文标签: PluginwebpackhtmlLoadertype
版权声明:本文标题:解决html-webpack-plugin在解析html时的“You may need an appropriate loader to handle this file type.”问题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1726296591a1064685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论