diff --git a/example/components/Logo.svg b/example/components/Logo.svg
new file mode 100644
index 0000000..e18148e
--- /dev/null
+++ b/example/components/Logo.svg
@@ -0,0 +1,16 @@
+
\ No newline at end of file
diff --git a/example/pages/index.vue b/example/pages/index.vue
index 5788f5c..9163349 100644
--- a/example/pages/index.vue
+++ b/example/pages/index.vue
@@ -4,6 +4,7 @@
+
diff --git a/src/index.ts b/src/index.ts
index 10fc6db..fd680a4 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -66,7 +66,8 @@ const componentsModule: Module = function () {
console.warn('Components directory not found: `' + dirPath + '`')
}
- const extensions = dirOptions.extensions || builder.supportedExtensions
+ const supportedExtensions = ['svg', ...builder.supportedExtensions]
+ const extensions = dirOptions.extensions || supportedExtensions
return {
...dirOptions,
diff --git a/src/scan.ts b/src/scan.ts
index 94da6da..f00ea48 100644
--- a/src/scan.ts
+++ b/src/scan.ts
@@ -67,6 +67,7 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<
const chunkName = 'components/' + kebabName
let component = {
+ svg: shortPath.endsWith('.svg'),
filePath,
pascalName,
kebabName,
diff --git a/templates/components/index.js b/templates/components/index.js
index fb07b7d..4919527 100644
--- a/templates/components/index.js
+++ b/templates/components/index.js
@@ -1,11 +1,24 @@
import { wrapFunctional } from './utils'
-<%= options.getComponents().map(c => {
+<%
+const rawComponents = options.getComponents()
+const components = []
+const svgs = []
+for (const c of rawComponents) {
+ if (c.svg) {
+ svgs.push(c)
+ } else {
+ components.push(c)
+ }
+}
+%>
+
+<%= components.map(c => {
const exp = c.pascalName === c.export ? c.pascalName : `${c.export} as ${c.pascalName}`
return `export { ${exp} } from '../${relativeToBuild(c.filePath)}'`
}).join('\n') %>
-<%= options.getComponents().map(c => {
+<%= components.map(c => {
const exp = c.export === 'default' ? `c.default || c` : `c['${c.export}']`
return `export const Lazy${c.pascalName} = import('../${relativeToBuild(c.filePath)}' /* webpackChunkName: "${c.chunkName}" */).then(c => wrapFunctional(${exp}))`
}).join('\n') %>
diff --git a/templates/components/plugin.js b/templates/components/plugin.js
index c770000..098f70a 100644
--- a/templates/components/plugin.js
+++ b/templates/components/plugin.js
@@ -1,7 +1,18 @@
import Vue from 'vue'
import { wrapFunctional } from './utils'
-<% const components = options.getComponents() %>
+<%
+const rawComponents = options.getComponents()
+const components = []
+const svgs = []
+for (const c of rawComponents) {
+ if (c.svg) {
+ svgs.push(c)
+ } else {
+ components.push(c)
+ }
+}
+%>
const components = {
<%= components.map(c => {
@@ -10,7 +21,22 @@ const components = {
}).join(',\n') %>
}
+const svgs = {}
+
+<% for (const c of svgs) { %>
+svgs[`<%= c.pascalName %>`] = {
+ render (h) {
+ const src = require('../<%= relativeToBuild(c.filePath) %>' /* webpackChunkName: "<%= c.chunkName %>" */)
+ return h('img', { attrs: { src } })
+ }
+}
+<% } %>
+
for (const name in components) {
Vue.component(name, components[name])
Vue.component('Lazy' + name, components[name])
}
+
+for (const name in svgs) {
+ Vue.component(name, svgs[name])
+}