Created
August 15, 2021 19:32
-
-
Save hazg/90ed71030e9284f1ca24eaea6f7769ca to your computer and use it in GitHub Desktop.
Rollup + svelte + rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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