rollup-modules.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. let input = path.join('tmp/tsc-output', pkgStruct.srcDir, 'main.js')
  29. return {
  30. input,
  31. output: {
  32. file: path.join(pkgStruct.dir, 'main.js'),
  33. format: 'esm',
  34. banner,
  35. sourcemap: isDev
  36. },
  37. plugins: [
  38. {
  39. resolveId(id, source) {
  40. if (id === input) {
  41. return null
  42. }
  43. else if (id.match(/vdom$/) && source.match('packages/core')) {
  44. return { id, external: true, moduleSideEffects: true }
  45. }
  46. else if (isNamedPkg(id)) {
  47. return { id, external: true }
  48. }
  49. }
  50. },
  51. nodeResolve(),
  52. TEMPLATE_PLUGIN,
  53. ...(isDev ? SOURCEMAP_PLUGINS : []),
  54. {
  55. resolveId(id) {
  56. if (isScssPath(id) && isRelPath(id)) {
  57. return { id: './' + path.basename(id, '.scss') + '.css', external: true }
  58. }
  59. return null
  60. }
  61. }
  62. ],
  63. watch: WATCH_OPTIONS,
  64. onwarn
  65. }
  66. }