Skip to content

Commit

Permalink
revert back to original entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
freddie-nelson committed Feb 4, 2021
1 parent 17b1f9b commit 76b5cd6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue3-slider",
"version": "1.2.1",
"version": "1.2.2",
"author": "Freddie Nelson <[email protected]> (https://freddienelson.co.uk)",
"description": "A modern, customizable slider built entirely in Vue.js 3 with TypeScript in under 3KB (gzipped) and dependency free.",
"keywords": [
Expand Down
25 changes: 25 additions & 0 deletions src/entry.esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { App, DefineComponent, Plugin } from 'vue';

// Import vue component
import component from '@/vue3-slider.vue';

// Define typescript interfaces for installable component
type InstallableComponent = DefineComponent & { install: Exclude<Plugin['install'], undefined> };

// Default export is installable instance of component.
// IIFE injects install function into component, allowing component
// to be registered via Vue.use() as well as Vue.component(),
export default /*#__PURE__*/((): InstallableComponent => {
// Assign InstallableComponent type
const installable = component as unknown as InstallableComponent;

// Attach install function executed by Vue.use()
installable.install = (app: App) => {
app.component('Vue3Slider', installable);
};
return installable;
})();

// It's possible to expose named exports when writing components that can
// also be used as directives, etc. - eg. import { RollupDemoDirective } from 'rollup-demo';
// export const RollupDemoDirective = directive;
32 changes: 9 additions & 23 deletions src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { App, DefineComponent, Plugin } from 'vue';
// iife/cjs usage extends esm default export - so import it all
import component, * as namedExports from '@/entry.esm';

// Import vue component
import component from '@/vue3-slider.vue';
// Attach named exports directly to component. IIFE/CJS will
// only expose one global var, with named exports exposed as properties of
// that global var (eg. plugin.namedExport)
Object.entries(namedExports).forEach(([exportName, exported]) => {
if (exportName !== 'default') component[exportName] = exported;
});

// Define typescript interfaces for installable component
type InstallableComponent = DefineComponent & { install: Exclude<Plugin['install'], undefined> };

// Default export is installable instance of component.
// IIFE injects install function into component, allowing component
// to be registered via Vue.use() as well as Vue.component(),
export default /*#__PURE__*/((): InstallableComponent => {
// Assign InstallableComponent type
const installable = component as unknown as InstallableComponent;

// Attach install function executed by Vue.use()
installable.install = (app: App) => {
app.component('Vue3Slider', installable);
};
return installable;
})();

// It's possible to expose named exports when writing components that can
// also be used as directives, etc. - eg. import { RollupDemoDirective } from 'rollup-demo';
// export const RollupDemoDirective = directive;
export default component as typeof component & Exclude<typeof namedExports, 'default'>;

0 comments on commit 76b5cd6

Please sign in to comment.