Skip to content

Instantly share code, notes, and snippets.

@enyo
Created February 11, 2022 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save enyo/3a583f30cd27e6a007e53bd0c71d2acb to your computer and use it in GitHub Desktop.
Save enyo/3a583f30cd27e6a007e53bd0c71d2acb to your computer and use it in GitHub Desktop.
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import svelte from 'rollup-plugin-svelte'
import { terser } from 'rollup-plugin-terser'
import sveltePreprocess from 'svelte-preprocess'
const production = !process.env.ROLLUP_WATCH
export default {
// The file we created with our web component wrapper.
input: 'web-components.ts',
output: {
sourcemap: !production,
format: 'iife',
name: 'app',
// We output it to public. This way, our svelte kit
// app will also host the web components.
file: 'public/web-components.js',
},
// Normal rollup svelte configuration. Nothing fancy
// happening here.
plugins: [
typescript(),
svelte({
preprocess: sveltePreprocess({
sourceMap: !production,
postcss: true,
}),
// We just make sure that no global CSS is injeced
// into the page that imports this script.
emitCss: false,
compilerOptions: {
dev: !production,
// customElement: true,
},
}),
resolve(),
commonjs(),
// Minify the production build (npm run build)
production && terser(),
],
}
@vish01
Copy link

vish01 commented Apr 16, 2022

Do you have a repo where I can see how the entire folder structure looks like for using svelte components as web components? Where does this rollup.config.js file goes and how is it being used? There needs to be some setup in svelte.config that says "use this rollup as well", no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment