Skip to content

Commit c90a8ed

Browse files
fix: use image name function when using inline query
1 parent 9df6300 commit c90a8ed

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/module.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export default function nuxtSvgLoader() {
77
options.svgoConfig = options.svgo
88
}
99

10-
this.extendBuild(setupVueSvgLoader(options))
10+
const fileName = this.nuxt.options.build.filenames.img(this.nuxt.options.dev)
11+
12+
this.extendBuild(setupVueSvgLoader(options, fileName))
1113
}
1214

1315
const svgRulePredicate = rule => rule.test && rule.test.test('.svg')
1416

15-
const setupVueSvgLoader = options => (config) => {
17+
const setupVueSvgLoader = (options, fileName) => (config) => {
1618
// https://github.com/egoist/svg-to-vue-component#nuxtjs-2
1719
const imageLoaderRule = config.module.rules.find(svgRulePredicate)
1820

@@ -33,7 +35,7 @@ const setupVueSvgLoader = options => (config) => {
3335
resourceQuery: /inline/,
3436
loader: 'file-loader',
3537
query: {
36-
name: '[name].[ext]'
38+
name: fileName
3739
}
3840
},
3941
{

test/__snapshots__/module.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`ssr correctly load SVG as background image 1`] = `
44
"<!doctype html>
55
<html data-n-head-ssr data-n-head=\\"\\">
66
<head data-n-head=\\"\\">
7-
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"17cfdfa9:0\\">.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999}.nuxt-progress.nuxt-progress-notransition{transition:none}.nuxt-progress-failed{background-color:red}</style><style data-vue-ssr-id=\\"7bcfa2f0:0\\">h1{background:url(/_nuxt/NuxtTwo.svg)}</style>
7+
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"17cfdfa9:0\\">.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999}.nuxt-progress.nuxt-progress-notransition{transition:none}.nuxt-progress-failed{background-color:red}</style><style data-vue-ssr-id=\\"7bcfa2f0:0\\">h1{background:url(/_nuxt/img/a88f1f4.svg)}</style>
88
</head>
99
<body data-n-head=\\"\\">
1010
<div data-server-rendered=\\"true\\" id=\\"__nuxt\\"><!----><div id=\\"__layout\\"><div><h1>-</h1> <h2>-</h2></div></div></div><script>window.__NUXT__={layout:\\"default\\",data:[{}],error:null,serverRendered:true};</script><script src=\\"/_nuxt/runtime.js\\" defer></script><script src=\\"/_nuxt/pages/background-image.js\\" defer></script><script src=\\"/_nuxt/commons.app.js\\" defer></script><script src=\\"/_nuxt/app.js\\" defer></script>

0 commit comments

Comments
 (0)