jlengstorf / learn-rollup

This is an example project to accompany a tutorial on using Rollup.
https://code.lengstorf.com/learn-rollup-js/
ISC License
191 stars 61 forks source link

How do I exclude files from the bundle? #42

Closed backspaces closed 6 years ago

backspaces commented 6 years ago

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?

jlengstorf commented 6 years ago

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.

backspaces commented 6 years ago

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'
    }
  ]
}