From 5b83f9f752e574d999c01a818795fb6e06b44884 Mon Sep 17 00:00:00 2001 From: Simon Moore Date: Mon, 22 Apr 2019 15:12:25 +0100 Subject: [PATCH] Fix Vue wrapper packaging issue (#236) * Fix Vue wrapper packaging issue * Export individual components as well as Vue plug-in entrypoint --- packages/vue/package.json | 2 +- packages/vue/src/index.js | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/vue/package.json b/packages/vue/package.json index 09dc373dd0..6743a64791 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -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", diff --git a/packages/vue/src/index.js b/packages/vue/src/index.js index bc7d93d0d5..ac2728efcb 100644 --- a/packages/vue/src/index.js +++ b/packages/vue/src/index.js @@ -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)) { @@ -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 };