Skip to content

feat(nuxt): add usePretranspiled option #3048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/markdown/intro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _after_ Bootstrap SCSS to ensure variables are set up correctly.
**Note**: _Requires webpack configuration to load CSS/SCSS files
([official guide](https://webpack.js.org/guides/asset-management/#loading-css))_.

## Nuxt.js plugin module
## Nuxt.js Module

[Nuxt.js](https://nuxtjs.org) version {{ nuxtVersion }} (or greater) is recommended.

Expand Down Expand Up @@ -153,6 +153,14 @@ module.exports = {
}
```

### Using pretranspiled version of BootstrapVue for Nuxt.js

Nuxt module uses precompiled version of BootstrapVue for faster development builds and source of
BootstrapVue for higher quality production builds.

You can override this option using `usePretranspiled` option. Setting to `true` uses `es/` instead
of `src/`. By default is enabled for development mode only.

## Vue CLI 2

BootstrapVue has two Vue CLI templates available:
Expand Down
9 changes: 7 additions & 2 deletions nuxt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ module.exports = function nuxtBootstrapVue(moduleOptions = {}) {
this.options.css.unshift('bootstrap/dist/css/bootstrap.css')
}

// Transpile src
// Transpile src/
this.options.build.transpile.push('bootstrap-vue/src')

const templateOptions = {}
// Use es/ or src/
const usePretranspiled = pickFirst(options.usePretranspiled, this.options.dev)

const templateOptions = {
dist: usePretranspiled ? 'es' : 'src'
}

// TODO: Also add support for individual components & directives
for (const type of ['componentPlugins', 'directivePlugins']) {
Expand Down
8 changes: 4 additions & 4 deletions nuxt/plugin.template.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Vue from 'vue'
<% if (options.componentPlugins.length || options.directivePlugins.length) { %><%=
options.componentPlugins.reduce((acc, p) => (acc += `import ${p[0]} from 'bootstrap-vue/es/components/${p[1]}'\n` ), '') %><%=
options.directivePlugins.reduce((acc, p) => (acc += `import ${p[0]} from 'bootstrap-vue/es/directives/${p[1]}'\n` ), '') %>
options.componentPlugins.reduce((acc, p) => (acc += `import ${p[0]} from 'bootstrap-vue/${options.dist}/components/${p[1]}'\n` ), '') %><%=
options.directivePlugins.reduce((acc, p) => (acc += `import ${p[0]} from 'bootstrap-vue/${options.dist}/directives/${p[1]}'\n` ), '') %>

<% if (options.config) { %>
import BVConfigPlugin from 'bootstrap-vue/es/bv-config'
import BVConfigPlugin from 'bootstrap-vue/<%= options.dist %>/bv-config'

Vue.use(BVConfigPlugin, <%= JSON.stringify(options.config, undefined, 2) %>)
<% } %>
Expand All @@ -13,7 +13,7 @@ Vue.use(BVConfigPlugin, <%= JSON.stringify(options.config, undefined, 2) %>)
options.componentPlugins.reduce((acc, p) => (acc += `Vue.use(${p[0]})\n` ), '') %><%=
options.directivePlugins.reduce((acc, p) => (acc += `Vue.use(${p[0]})\n` ), '') %>
<% } else { %>
import BootstrapVue from 'bootstrap-vue/es'
import BootstrapVue from 'bootstrap-vue/<%= options.dist %>'

Vue.use(BootstrapVue, <%= JSON.stringify(options.config || {}, undefined, 2) %>)
<% } %>