jlengstorf/learn-rollup

How do I exclude files from the bundle?

backspaces opened this issue · 2 comments

I didn't see you configuring rollup to eliminate files from the rollup. I've asked around and haven't found an answer. Can it be done?

It can be done. :)

You're looking for the external option. See the big list of options and scroll down a bit to see details on how to use it in your config.

Thanks. Turns out that the exclusion I needed was for an iife so needed globals. But I also needed external for an es6 rollup. Used functions for both! Yay! Thanks again for the article and response.

Looks like this:

function externals (id) { return id.includes('/dist/') }
function globals (id) {
  const jsNames = {
    'stats.wrapper.js': 'Stats',
    'dat.gui.wrapper.js': 'dat',
    'three.wrapper.js': 'THREE'
  }
  const fileName = id.replace(/^.*\//, '')
  return jsNames[fileName]
}

export default {
  input: 'src/AS.js',
  banner: '/* eslint-disable */',
  external: externals,
  output: [
    { file: 'dist/AS.js',
      format: 'iife',
      globals: globals,
      name: 'AS'
    },
    { file: 'dist/AS.module.js',
      format: 'es'
    }
  ]
}