Skip to content

Instantly share code, notes, and snippets.

@hazg
Created August 15, 2021 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hazg/0efd24bd23ec879c23cac28dd29f33f5 to your computer and use it in GitHub Desktop.
Save hazg/0efd24bd23ec879c23cac28dd29f33f5 to your computer and use it in GitHub Desktop.
Rollup + rails + svelte
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import svelte from 'rollup-plugin-svelte'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
import del from 'rollup-plugin-delete'
import sveltePreprocess from 'svelte-preprocess'
import uglify from 'rollup-plugin-uglify-es'
import visualizer from 'rollup-plugin-visualizer'
import replace from '@rollup/plugin-replace'
import scss from 'rollup-plugin-scss'
import notify from '@aredridel/rollup-plugin-notify'
import execute from 'rollup-plugin-execute'
const production = !process.env.ROLLUP_WATCH
export default {
input: "app/javascript/bundle.js",
perf: true,
cache: !production,
treeshake: production,
output: {
sourcemap: !production,
format: "esm",
name: "app",
dir: "public/packs",
},
preserveEntrySignatures: 'struct',
plugins: [
notify(),
execute([
'wmctrl -a Chrome',
'xdotool key "ctrl+1"',
'xdotool key F5'
]),
del({ targets: 'public/packs/*.(js|map)' }),
svelte({
onwarn: (warning, handler) => {
const { code, frame, filename } = warning
// Skip app.svelte because bootstrap
if (code === "css-unused-selector" && filename == 'app/javascript/app.svelte') {
return;
}
handler(warning)
},
compilerOptions: {
dev: !production,
},
emitCss: true,
preprocess: sveltePreprocess({ /* options */ }),
}),
resolve({
extensions: ['.svelte', '.js'],
preferBuiltins: false,
browser: true,
dedupe: importee =>
importee === "svelte" || importee.startsWith("svelte/"),
}),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify(
production ? 'production' : 'development'
)
}),
commonjs(/*{ sourceMap: false }*/),
scss({
output: "public/packs/bundle.css",
failOnError: true,
}),
production && uglify(),
production && terser(),
!production && livereload({ watch: './public/packs' }),
production && visualizer({
filename: 'public/stats.html',
template: 'treemap',
open: true,
}),
],
watch: {
clearScreen: true,
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment