Skip to content

Commit 8a391a1

Browse files
Shyam-Chenegoist
authored andcommitted
feat(build): support commonjs modules (#4)
closes #3
1 parent 71674bc commit 8a391a1

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "vue-router-prefetch",
33
"version": "1.0.0",
44
"description": "Prefetch the route components of router-link in viewport.",
5-
"main": "dist/index.js",
6-
"module": "dist/index.js",
5+
"main": "dist/vue-router-prefetch.cjs.js",
6+
"module": "dist/vue-router-prefetch.esm.js",
77
"files": [
88
"dist"
99
],

rollup.config.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
export default {
22
input: 'src/index.js',
3-
output: {
4-
format: 'es',
5-
file: 'dist/index.js'
6-
},
3+
output: [
4+
{
5+
file: 'dist/vue-router-prefetch.cjs.js',
6+
format: 'cjs',
7+
exports: 'named'
8+
},
9+
{ file: 'dist/vue-router-prefetch.esm.js', format: 'es' }
10+
],
711
plugins: [
812
require('rollup-plugin-node-resolve')(),
913
require('rollup-plugin-buble')({

src/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import prefetch from './prefetch'
22
import { canPrefetch, supportIntersectionObserver } from './utils'
33

4-
export { prefetch }
5-
6-
export default (Vue, { componentName = 'RouterLink' } = {}) => {
4+
function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) {
75
const observer =
86
supportIntersectionObserver &&
97
new window.IntersectionObserver(entries => {
@@ -83,3 +81,11 @@ export default (Vue, { componentName = 'RouterLink' } = {}) => {
8381

8482
Vue.component(Link.name, Link)
8583
}
84+
85+
export {
86+
prefetch,
87+
// Export as `install` to make `Vue.use(require('vue-router-prefetch'))` work
88+
installRouterPrefetch as install
89+
}
90+
91+
export default installRouterPrefetch

0 commit comments

Comments
 (0)