使用 es6 模板字符串加载器导入 html 文件 [英] Importing html files with es6 template string loader
本文介绍了使用 es6 模板字符串加载器导入 html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 es6 模板字符串加载器将我的模板导入到我的 js 中.一>.在我的情况下唯一的区别是我不想包含 css,只包含 html.我的代码如下:
I want to import my templates into my js with es6 template string loader. The only difference in my case is that I don't want to include css, only html. My code is as follows:
import app from '../../bootstrap.js';
import template from './header.html';
app.component('siteHeader', {
template
});
我的错误是Uncaught SyntaxError: Unexpected token export
.
推荐答案
我最近需要做同样的事情,我就是这样做的.
I recently needed to do the same thing, and this is how I did it.
1. 我使用了 npm 模块 html-loader
,而不是 es6-template-string-loader
1. I used the npm module html-loader
, instead of es6-template-string-loader
2. 添加到 webpack.config.js
...
module: {
rules: [
{
test: /.html$/,
exclude: /node_modules/,
use: {loader: 'html-loader'}
}
]
}
...
Webpack 1(已弃用,但来自原始答案):
...
module: {
loaders: [
{
test: /.html$/,
loader: "html-loader"
}
]
}
...
3.在您的 JS 文件中使用
3. Use in your JS files
import template from './header.html';
这篇关于使用 es6 模板字符串加载器导入 html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文