Skip to content

Commit 2e22691

Browse files
committed
same esm/cjs/multiple-entrypoint strategy as standard/premium
1 parent 5211e6e commit 2e22691

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fullcalendar/vue",
3-
"version": "6.1.1",
3+
"version": "6.1.2",
44
"title": "FullCalendar Vue 2 Component",
55
"description": "The official Vue 2 component for FullCalendar",
66
"keywords": [
@@ -84,5 +84,6 @@
8484
"files": [
8585
"dist",
8686
"src"
87-
]
87+
],
88+
"sideEffects": false
8889
}

rollup.config.js

+61-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import pkgJson from './package.json'
12

2-
const EXTERNAL_GLOBALS = {
3+
const [ourPkgNames, otherPkgNames] = getDepNames()
4+
const externalGlobals = {
35
vue: 'Vue',
46
'@fullcalendar/core': 'FullCalendar',
57
'@fullcalendar/core/internal': 'FullCalendar.Internal'
@@ -14,7 +16,10 @@ export default [
1416
format: 'cjs',
1517
exports: 'named'
1618
},
17-
external: Object.keys(EXTERNAL_GLOBALS)
19+
plugins: [
20+
externalizePkgsPlugin(ourPkgNames, '.cjs'),
21+
externalizePkgsPlugin(otherPkgNames),
22+
],
1823
},
1924

2025
// IIFE
@@ -25,8 +30,60 @@ export default [
2530
format: 'iife',
2631
name: 'FullCalendar.Vue',
2732
exports: 'named',
28-
globals: EXTERNAL_GLOBALS
33+
globals: externalGlobals
2934
},
30-
external: Object.keys(EXTERNAL_GLOBALS)
35+
plugins: [
36+
externalizePkgsPlugin(ourPkgNames),
37+
externalizePkgsPlugin(otherPkgNames),
38+
],
3139
},
3240
]
41+
42+
// plugins & utils
43+
// -------------------------------------------------------------------------------------------------
44+
45+
function getDepNames() {
46+
const pkgNames = Object.keys({
47+
...pkgJson.dependencies,
48+
...pkgJson.peerDependencies,
49+
...pkgJson.optionalDependencies,
50+
})
51+
const ourPkgNames = []
52+
const otherPkgNames = []
53+
54+
for (const pkgName of pkgNames) {
55+
if (pkgName.match(/^@fullcalendar\//)) {
56+
ourPkgNames.push(pkgName)
57+
} else {
58+
otherPkgNames.push(pkgName)
59+
}
60+
}
61+
62+
return [ourPkgNames, otherPkgNames]
63+
}
64+
65+
function externalizePkgsPlugin(pkgNames, forceExtension) {
66+
return {
67+
name: 'externalize-pkgs',
68+
resolveId(importId) {
69+
if (!isImportRelative(importId)) {
70+
for (const pkgName of pkgNames) {
71+
if (importId === pkgName || importId.startsWith(pkgName + '/')) {
72+
if (forceExtension) {
73+
if (importId === pkgName) {
74+
importId += '/index' + forceExtension
75+
} else {
76+
importId += forceExtension
77+
}
78+
}
79+
return { id: importId, external: true }
80+
}
81+
}
82+
}
83+
},
84+
}
85+
}
86+
87+
function isImportRelative(importId) {
88+
return importId.startsWith('./') || importId.startsWith('../')
89+
}

0 commit comments

Comments
 (0)