forked from EnergySage/es-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuxt-components.vue
95 lines (90 loc) · 3.12 KB
/
nuxt-components.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<div>
<h1>
Nuxt module usage
</h1>
<h2>
es-vue-base Module
</h2>
<p>
Nuxt now suggest
<b-link
target="_blank"
href="https://nuxtjs.org/docs/directory-structure/components/#components-discovery">
component discovery
</b-link>
as the preferred method of importing components into your application. Doing so allows webpack to
<b-link
target="_blank"
href="https://webpack.js.org/guides/tree-shaking/">
tree shake
</b-link>
components the way it determines is most performant. With the use of our included nuxt module you
can turn on this feature for our design system components.
</p>
<h3>
Auto Include Everything
</h3>
<p>
There are a two main ways to configure the included module. The default configuration is to auto
import all components and icons. This will allow you to use all possible design system components
and icons without having to import them manually. When doing a production build you will end up with
significantly more bundle files; even for unused components. Regardless, the only component bundles
that are loaded are ones you've used in your application. This is the easiest method by far and requires
little maintanance going forward. The downside to this can be significantly longer build times. Especially
when components are being added and updated regularly.
</p>
<pre>
<code>
nuxt.config.js:
buildModules: [
'@energysage/es-vue-base/nuxt'
],
</code>
</pre>
<h2>
Bootstrap-Vue Module
</h2>
<p>
To start we first recommend using bootstrap-vue's
<b-link
target="_blank"
href="https://bootstrap-vue.org/docs/#nuxtjs-module">
nuxt module
</b-link>
and their suggested pattern for
<b-link
target="_blank"
href="https://bootstrap-vue.org/docs/#tree-shaking-with-nuxtjs">
tree shaking
</b-link>. With this pattern there is a
<b-link
target="_blank"
href="https://github.com/bootstrap-vue/bootstrap-vue/issues/5713">
bug
</b-link>
that results in bootstrap-vue's icon bundle always being included. Below is one way on how to prevent
the bundle from being included.
</p>
<pre>
<code>
$ npm install -D null-loader
nuxt.config.js:
build: {
extend(config) {
// Prevents bootstrap-vue icons from being unitentionally included
config.module.rules.push({
test: /bootstrap-vue\/src\/icons\/icons/,
use: 'null-loader',
});
},
},
</code>
</pre>
</div>
</template>
<script>
export default {
name: 'NuxtModule',
};
</script>