Skip to content

Instantly share code, notes, and snippets.

@Electroid
Created February 12, 2021 23:45
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Electroid/7d55c0023fe6ef3277f7c4fe361a58f0 to your computer and use it in GitHub Desktop.
Save Electroid/7d55c0023fe6ef3277f7c4fe361a58f0 to your computer and use it in GitHub Desktop.
Rollup config for ESM Cloudflare Workers
import commonjs from '@rollup/plugin-commonjs'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import copyAssets from 'rollup-plugin-copy-imported-assets'
import nodePolyfills from 'rollup-plugin-node-polyfills'
import nodeGlobals from 'rollup-plugin-node-globals'
// https://rollupjs.org/guide/en/#configuration-files
export default {
input: 'src/index.mjs',
output: {
exports: 'named',
format: 'es',
preserveModulesRoot: 'src',
preserveModules: false,
sourcemap: false,
dir: 'dist',
entryFileNames: '[name].mjs',
assetFileNames: 'assets/[name][extname]',
},
// See https://github.com/rollup/awesome for more plugins.
plugins: [
// Converts CommonJS modules to ES6.
commonjs({
transformMixedEsModules: true
}),
// Resolves JSON files as objects.
json(),
// Resolves non-JavaScript files, like images or text.
copyAssets({
include: /\./,
exclude: /\.(c|m)(j|t)sx?$/
}),
// Resolves NPM packages from node_modules/.
nodeResolve({
browser: true
}),
// Polyfills NodeJS APIs, when possible.
// NOTE: Can be removed, especially if you're running into
// weird complication errors from some of your dependencies.
nodePolyfills({
crypto: true
}),
// Polyfills NodeJS global variables (e.g. process).
// NOTE: Can be removed, especially if you're running into
// weird complication errors from some of your dependencies.
nodeGlobals(),
// Resolves non-toplevel imports using static analysis.
dynamicImportVars({
warnOnError: true
})
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment