Rollup/repo structure for multiple rollups?

This is a slightly off-topic question for other developers out there who are using Rollups on a project with more than one Autotask.

I'm curious if you would care to share how you are configuring your rollup config to support multiple multiple autotask scripts?

In the Autotask examples so generously provided by OZ, the Rollup example only supports one AT as a time.

Thanks in advance,
Michael

Hi @mpaler,

This is easily possible using both rollup and webpack.

Rollup

With rollup you should change your config to export an array of objects, each corresponding to an autotask. Something like this:

const options = {
  plugins: [resolve({ preferBuiltins: true }), commonjs(), json({ compact: true }), typescript()],
  external: [...builtins, 'ethers', 'web3', 'axios', /^defender-relay-client(\/.*)?$/],
};

export default [
  {
    input: 'src/autotaskA.ts',
    output: {
      file: 'dist/autotaskA.js',
      format: 'cjs',
    },
    ...options,
  },
  {
    input: 'src/autotaskB.ts',
    output: {
      file: 'dist/autotaskB.js',
      format: 'cjs',
    },
    ...options,
  },
];

Webpack

Its a bit more straightforward to do with webpack and doesnt duplicate as much code. In webpack.config.js change entry to an object, adding an entry for each autotask script:

entry: {
  autotaskA: './src/autotaskA.ts',
  autotaskB: './src/autotaskB.ts',
}

Then you will need to change filename in output to this:

output: {
  filename: '[name].js',
  ...
},

Build as normal and you should see 2 separate files for each autotask.

1 Like

Thanks for the tips!