rollup-modules.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const path = require('path')
  2. const nodeResolve = require('@rollup/plugin-node-resolve')
  3. const { renderBanner, isRelPath, isNamedPkg, isScssPath, TEMPLATE_PLUGIN, SOURCEMAP_PLUGINS, WATCH_OPTIONS, onwarn } = require('./rollup-util')
  4. const { pkgStructs } = require('./pkg-struct')
  5. const { copyFile } = require('./util')
  6. module.exports = function(isDev) {
  7. let configs = pkgStructs.filter((pkgStruct) => !pkgStruct.isBundle)
  8. .map((pkgStruct) => buildPkgConfig(pkgStruct, isDev))
  9. // needed to have this in separate file because rollup wasn't understanding that it has side effects and needed to go before the @fullcalendar/core import
  10. // added bonuses:
  11. // - the import statement doesn't import any vars, which will maybe hint to the build env that there are side effects
  12. // - rollup-plugin-dts needed to handle the .d.ts files separately anyway
  13. configs.push({
  14. input: 'tmp/tsc-output/packages/core/src/vdom.js',
  15. output: {
  16. file: 'packages/core/vdom.js', // TODO: use pkgStruct to know this
  17. format: 'esm',
  18. sourcemap: isDev
  19. },
  20. external(id) {
  21. return isNamedPkg(id)
  22. }
  23. })
  24. return configs
  25. }
  26. function buildPkgConfig(pkgStruct, isDev) {
  27. let banner = renderBanner(pkgStruct.jsonObj)
  28. return {
  29. input: path.join('tmp/tsc-output', pkgStruct.srcDir, 'main.js'),
  30. output: {
  31. file: path.join(pkgStruct.dir, 'main.js'),
  32. format: 'esm',
  33. banner,
  34. sourcemap: isDev
  35. },
  36. external(id) {
  37. return isNamedPkg(id)
  38. },
  39. plugins: [
  40. {
  41. resolveId(id, source) {
  42. if (id.match(/vdom$/) && source.match('packages/core')) {
  43. return { id, external: true }
  44. }
  45. }
  46. },
  47. nodeResolve(),
  48. TEMPLATE_PLUGIN,
  49. ...(isDev ? SOURCEMAP_PLUGINS : []),
  50. {
  51. resolveId(id) {
  52. if (isScssPath(id) && isRelPath(id)) {
  53. return { id: './' + path.basename(id, '.scss') + '.css', external: true }
  54. }
  55. return null
  56. }
  57. }
  58. ],
  59. watch: WATCH_OPTIONS,
  60. onwarn
  61. }
  62. }