Search code examples
rolluprollupjs

rollupjs separate parent and child file


Is it possible to separate my parent and child code into two files while compiling using rollup?

Let's say I have a folder called base, it contains all the parent code where the other folder files will extend from.

I would love to separate the parent codes into one file, with the other child files that extend from the parent in other folder into another output file.

Is that possible?

Thanks


Solution

  • Yes, you can use an array or an object for the input option and rollup will generate a chunk for each entry:

    //...
    input: {
      parent: 'src/base/parent.js',
      child: 'src/child.js'
    }
    // or
    input: ['src/base/parent.js', 'src/child.js']
    

    And you can also use the manualChunks option: https://rollupjs.org/guide/en/#manualchunks

    // put everything from base directory into the parent chunk
    manualChunks(id) {
      if (id.includes('base')) {
        return 'parent';
      }
    }