我使用webpack编译电子邮件模板,在这些模板中我引用了我的公共路径中可用的静态资产
我已将我的公共路径设为
webpackConfig.output = {
filename: __DEV__ ? `[name].js` : `[name].[${config.compiler_hash_type}].js`,
publicPath: "https://my_website.com"
}
使用这些装载机
webpackConfig.module.loaders.push(
{ test: /\.woff(\?.*)?$/, loader: 'url?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/font-woff' },
{ test: /\.woff2(\?.*)?$/, loader: 'url?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/font-woff2' },
{ test: /\.otf(\?.*)?$/, loader: 'file?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=font/opentype' },
{ test: /\.ttf(\?.*)?$/, loader: 'url?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=application/octet-stream' },
{ test: /\.eot(\?.*)?$/, loader: 'file?prefix=fonts/&name=fonts/[name].[ext]' },
{ test: /\.svg(\?.*)?$/, loader: 'url?prefix=fonts/&name=fonts/[name].[ext]&limit=10000&mimetype=image/svg+xml' },
{ test: /\.(png|jpg)$/, loader: 'url?limit=8192' },
{ test: /\.(mp3|wav)$/, loader: 'file?prefix=sounds/&name=sounds/[name].[ext]&limit=10000&mimetype=audio/mpeg3' }
)
然而,webpack将它们编译为使用相对路径,所以在电子邮件中,它们就像这样看起来
<img href="/public/images/abc.png"...
这显然不会起作用
如何强制它使用完整的绝对URL?