Skip to content

Commit

Permalink
Fix Vue wrapper packaging issue (#236)
Browse files Browse the repository at this point in the history
* Fix Vue wrapper packaging issue

* Export individual components as well as Vue plug-in entrypoint
  • Loading branch information
moores2 authored and cal-smith committed Apr 22, 2019
1 parent 7556cef commit 5b83f9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@carbon/charts-vue",
"version": "0.11.11",
"description": "Carbon charting components for Vue",
"main": "index.js",
"main": "charts-vue.umd.min.js",
"scripts": {
"build": "bash build.sh",
"lint": "vue-cli-service lint ./src/index.js",
Expand Down
29 changes: 20 additions & 9 deletions packages/vue/src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
const ctx = require.context(
'./',
true,
/^(?!.*(?:\/_|-story\.vue|-test\.vue)).*\.vue$/
);
const components = ctx.keys().map(ctx);
import CcvBarChart from './ccv-bar-chart.vue';
import CcvDonutChart from './ccv-donut-chart.vue';
import CcvLineChart from './ccv-line-chart.vue';
import CcvPieChart from './ccv-pie-chart.vue';

const components = [CcvBarChart, CcvDonutChart, CcvLineChart, CcvPieChart];

/*
Allows the module to be used as a Vue plug-in, and has an install()
method (which is called when the plug-in loads) that registers all the
components.
*/
export default {
// options is an array of components to be registered
// e.g. ['c-button', 'c-modal']
install(Vue, options) {
if (typeof options === 'undefined') {
for (let c of components) {
Vue.component(c.default.name, c.default);
Vue.component(c.name, c);
}
} else {
if (!(options instanceof Array)) {
Expand All @@ -20,10 +25,16 @@ export default {

for (let c of components) {
// register only components specified in the options
if (options.includes(c.default.name)) {
Vue.component(c.default.name, c.default);
if (options.includes(c.name)) {
Vue.component(c.name, c);
}
}
}
},
};

/*
Allows import of individual components from the module, as an
alternative to loading them all via a Vue plug-in.
*/
export { CcvBarChart, CcvDonutChart, CcvLineChart, CcvPieChart };

0 comments on commit 5b83f9f

Please sign in to comment.