question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: In nuxt, only import/register components/directives passed in module options

See original GitHub issue

I’ve been able to setup a custom scss build for bootstrap to only include what I need, but I’m lacking an easy way to include in the JS build only the bootstrap-vue components I need so I can keep the bundle small.

The vue-bootstrap documentation > “Importing components and directives” shows how it’s possible for people in control of their webpack builds, but there’s no simple option for nuxt.

The only way I see right now is to remove module registration from nuxt.config.js (['@nuxtjs/bootstrap-vue', { css: false }]), and instead replicate the functionality of nuxt > index.js and plugin.js myself. I’d prefer the ability to do this declaratively by passing through the module options an array of components and another of directives by name to import and register globally.

I’ve been scouring the source of nuxt to see how/if the options defined for the module get passed from index.js (addPlugin) to plugin.js so I could take the arrays, import components/directives and register them with Vue globally. I’m just not sure how that’d work. Docs here > Template plugins seems to allude to needing lodash templates.

Anyone think this is useful and if it’s possible?

Thanks, Ben

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
webkonstantincommented, Jun 8, 2018

I had success setting up plugin like this

import Vue from 'vue'

if (process.server) {
  // Use full compiled version for ssr
  Vue.use(require('bootstrap-vue'))
} else {
  // Include only what you need for client
  // Note that you need to get .default from required module
  Vue.component('b-modal', require('bootstrap-vue/es/components/modal/modal').default)
}
1reaction
benmccallumcommented, Apr 3, 2018

Hi @pi0, thanks for jumping in here. Are you saying we can achieve importing only the bootstrap-vue components we need by following what was done in the lodash plugin? Got a link?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modules directory - Nuxt
Nuxt provides a higher-order module system that makes it possible to extend the core. Modules are functions that are called sequentially when booting...
Read more >
Built-in Components - Nuxt
This component is used to purposely render a component only on client-side. To import a component only on the client, register the component...
Read more >
The components Property - Nuxt
When set to true or an options object, Nuxt will include @nuxt/components and auto-import your components wherever you use them within your pages,...
Read more >
Plugins directory - Nuxt
Last but not least, add the module and the newly created plugin to the project configuration. nuxt.config.js module.exports = { modules: [ ...
Read more >
Configuration - Nuxt
Nuxt lets you define the CSS files/modules/libraries you want to set globally ... In your nuxt.config.js file, under the build option, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found