Skip to content

Commit 71c63f5

Browse files
aldarundkevinmarrec
authored andcommitted
feat: manual import of components (#125)
* feat: manual import - initial state (#110) * feat: manual import * fix: treeshake false situation
1 parent 7afbef9 commit 71c63f5

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

lib/templates/plugin.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import Vue from 'vue'
22
import Vuetify from '<%= options.treeShake ? 'vuetify/lib' : 'vuetify' %>'
3+
<%
4+
const libImports = [
5+
{ key: 'components', location: 'vuetify/lib'},
6+
{ key: 'transitions', location: 'vuetify/lib'},
7+
{ key: 'directives', location: 'vuetify/lib/directives'}
8+
]
9+
if (options.treeShake) {
10+
for (const lib of libImports) {
11+
if (options.treeShake[lib.key] && options.treeShake[lib.key].length > 0) {
12+
%>
13+
import { <%= options.treeShake[lib.key].join(', ') %> } from '<%= lib.location %>'
14+
<%
15+
}
16+
}
17+
}
18+
%>
19+
320
import options from './options'
421

5-
Vue.use(Vuetify)
22+
Vue.use(Vuetify, {
23+
<%
24+
if (options.treeShake) {
25+
for (const lib of libImports) {
26+
if (options.treeShake && options.treeShake[lib.key] && options.treeShake[lib.key].length > 0) {
27+
%>
28+
<%= lib.key %>: { <%= options.treeShake[lib.key].join(', ') %> }
29+
<%
30+
}
31+
}
32+
}
33+
%>
34+
})
635

736
export default (ctx) => {
837
const vuetifyOptions = typeof options === 'function' ? options(ctx) : options

test/fixture/pages/manual-import.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<v-container>
3+
<v-layout>
4+
<v-flex>
5+
<!-- eslint-disable-next-line vue/require-component-is -->
6+
<component is="v-chip">
7+
Default
8+
</component>
9+
</v-flex>
10+
</v-layout>
11+
</v-container>
12+
</template>

test/module.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,29 @@ describe.skip('enable treeShake', () => {
100100
expect(html).toContain('v-navigation-drawer--fixed')
101101
})
102102
})
103+
104+
describe.skip('manually import', () => {
105+
let nuxt
106+
107+
beforeAll(async () => {
108+
nuxt = new Nuxt({
109+
...config,
110+
vuetify: {
111+
treeShake: {
112+
components: ['VChip']
113+
}
114+
}
115+
})
116+
await nuxt.ready()
117+
await new Builder(nuxt).build()
118+
})
119+
120+
afterAll(async () => {
121+
await nuxt.close()
122+
})
123+
124+
test('render', async () => {
125+
const { html } = await nuxt.renderRoute('/manual-import')
126+
expect(html).toContain('v-chip__content')
127+
})
128+
})

0 commit comments

Comments
 (0)