bili icon indicating copy to clipboard operation
bili copied to clipboard

How to output multiple bundles

Open johannes-z opened this issue 5 years ago • 3 comments

If I have a config with an array of entry points (each of which have the same file name), how can I create multiple bundles?

The following example would output index.js twice, so the second bundle overwrites the first one...

input: [
  'src/project-a/index.ts',
  'src/project-b/index.ts',
]

johannes-z avatar Dec 04 '19 15:12 johannes-z

I'm having a similar issue, I can't seem to find a clear way to configure output directories relative to the individual inputs...?

remnantdotdev avatar Apr 15 '20 14:04 remnantdotdev

extendRollupConfig gets called for each input entry (if it's any array). I created an array with all the required information (path to the index file, amd-id, output filename), and use a global index variable:

import { Config } from 'bili'

import _config from './config.json'

let index = 0
const config: Config = {
  input: _config.bundles.map(bundle => bundle.entry),
  output: {
    format: 'amd-min',
    fileName: '[name][ext]',
    target: 'browser',
    sourceMap: false,
  },

  extendRollupConfig: config => {
    const bundle = _config.bundles[index++]
    config.outputConfig.entryFileNames = bundle.dist
    config.outputConfig.amd = {
      id: bundle.dist,
    }
    return config
  },
}

config.json looks like this:

{
  "bundles": [
    {
      "entry": "src/project-a/index.ts",
      "dist": "projecta.js"
    },
    {
      "entry": "src/project-b/index.ts",
      "dist": "projectb.js"
    }
  ]
}

johannes-z avatar Apr 15 '20 18:04 johannes-z

@johannes-z great workaround but this looks horrible. Yesterday I setup rollup manually with this feature and it took me 1 hour to compile my libs without Bili. It would be awesome to contribute to Bili but the maintenance is very low. It would be great to hear more feedback from the creators.

StarpTech avatar May 22 '20 08:05 StarpTech