[英]Webpack and svg-inline-loader doesn't work
I try to use svg-inline-loader
in multipages project.我尝试在多页项目中使用
svg-inline-loader
。
When i use it on index page it works fine当我在索引页面上使用它时它工作正常
<%= require('!svg-inline- loader!../../img/toolbar/'+firstBtn.iconName+'.svg') %>
but when i try to inject it in partial file it doesn't work.但是当我尝试将它注入部分文件时它不起作用。 I get
我明白了
Html Webpack Plugin:
ReferenceError: require is not defined
- lodash.templateSources[16]:7 eval
lodash.templateSources[16]:7:50
- loader.js:31 eval
[search.html?..]/[html-webpack-plugin]/lib/loader.js:31:106
- loader.js:36 module.exports
[search.html?..]/[html-webpack-plugin]/lib/loader.js:36:3
- index.js:422
[site.local]/[html-webpack-plugin]/index.js:422:16
My webpack config我的 webpack 配置
{
test: /\.html$/,
include: [path.resolve('src/html/partials/')],
use: ['html-loader']
},
new HtmlWebpackPlugin({
filename: 'index.html',
template: './html/pages/index.html',
chunks: ['main']
}),
new HtmlWebpackPlugin({
filename: 'login.html',
template: './html/pages/login.html',
chunks: ['login', 'main']
}),
new HtmlWebpackPlugin({
filename: 'search.html',
template: './html/pages/search.html',
chunks: ['main']
}),
my search page我的搜索页面
<% var toolbar = {
firstBtn: {
title: "City",
anchor: "login.html",
iconName: "city"
}
} %>
<%= _.template(require('../partials/header.html'))%>
<div class="container">
<div class="search">
<%= _.template(require('../partials/toolbar.html'))(toolbar)%>
</div>
and toolbar.html
where i want to load toolbar's variables和
toolbar.html
我想加载工具栏的变量
<div class="toolbar">
<%= require('!svg-inline-
loader!../../img/toolbar/'+firstBtn.iconName+'.svg') %>
</div>
How to solve this problem with HtmlWebpackPlugin.如何用 HtmlWebpackPlugin 解决这个问题。 Header's partial works fine before i inject svg-inline-loader
在我注入 svg-inline-loader 之前,标题的部分工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.