diff --git a/package.json b/package.json index 3dbc9ac67f..c61d9cdcba 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,11 @@ "cypress:gui": "cypress open --component", "cypress:update-snapshots": "cypress run --component --env type=base --config screenshotsFolder=cypress/snapshots/base" }, - "main": "dist/index.cjs", - "module": "dist/index.mjs", + "main": "dist/index.umd.js", + "module": "dist/index.esm.js", "exports": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" + "import": "./dist/index.esm.js", + "require": "./dist/index.umd.js" }, "files": [ "CHANGELOG.md", diff --git a/src/index.js b/src/index.js index 19c70217b2..91809e4148 100644 --- a/src/index.js +++ b/src/index.js @@ -19,9 +19,22 @@ * along with this program. If not, see . * */ +import * as NcComponents from './components/index.js' export * from './components/index.js' export * from './functions/index.js' export * from './directives/index.js' export * from './mixins/index.js' export * from './a11y/index.js' + +// Vue plugin to install all components using `Vue.use(NextcloudVue)` +export const NextcloudVue = { + /** + * @param {object} Vue The vue instance + */ + install: Vue => { + Object.values(NcComponents).forEach(component => { + Vue.component(component.name, component) + }) + }, +} diff --git a/src/install.js b/src/install.js deleted file mode 100644 index 8f3432b2ba..0000000000 --- a/src/install.js +++ /dev/null @@ -1,16 +0,0 @@ -import * as NcComponents from './components/index.js' - -/** - * @param {object} Vue The vue instance - */ -function install(Vue) { - Object.values(NcComponents).forEach((component) => { - Vue.component(component.name, component) - }) -} - -if (typeof window !== 'undefined' && window.Vue) { - install(window.Vue) -} - -export default install diff --git a/vite.config.mjs b/vite.config.mjs index 1631617aba..98c512ede7 100644 --- a/vite.config.mjs +++ b/vite.config.mjs @@ -1,12 +1,11 @@ import md5 from 'md5' -import glob from 'glob' import vue from '@vitejs/plugin-vue2' import { externals } from 'rollup-plugin-node-externals' import browserslistToEsbuild from 'browserslist-to-esbuild' import injectProcessEnv from 'rollup-plugin-inject-process-env' import { loadTranslations } from './resources/translations.mjs' import { fileURLToPath, URL } from 'url' -import { dirname, join, resolve } from 'path' +import { dirname, resolve } from 'path' import { defineConfig } from 'vite' import { readFileSync } from 'fs' @@ -83,40 +82,9 @@ export default defineConfig({ }, lib: { name: 'NextcloudVue', - entry: { - index: resolve(__dirname, 'src/index.js'), - install: join(__dirname, 'src', 'install.js'), - ...glob.sync('src/components/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/components/', 'Components/') - acc[name] = join(__dirname, item) - return acc - }, {}), - ...glob.sync('src/directives/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/directives/', 'Directives/') - acc[name] = join(__dirname, item) - return acc - }, {}), - ...glob.sync('src/functions/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/functions/', 'Functions/') - acc[name] = join(__dirname, item) - return acc - }, {}), - ...glob.sync('src/mixins/*/index.js').reduce((acc, item) => { - const name = item - .replace('/index.js', '') - .replace('src/mixins/', 'Mixins/') - acc[name] = join(__dirname, item) - return acc - }, {}), - }, + entry: resolve(__dirname, 'src/index.js'), fileName: (format, entry) => { - return `${entry}.${format.startsWith('es') ? 'mjs' : format}` + return `${entry}.${format === 'es' ? 'esm' : format}.js` }, }, },